(TTT) Post-round deathmatch script crashes server

I believe a script I made may be crashing my server. I’d appreciate if a LUA god could take a quick look and see if anything looks fishy.

Just something to note, PrintColor DOES work. It’s in another script on the server, so that’s not an issue.



if SERVER then

hook.Add("TTTEndRound", "PRDM", function()

	-- Initializing/default values PRDM winner vars
	prdmWinner = ""
	prdmWinnerKC = 0
	prdmWinnerENT = ""
	
	
	-- Setting PRDM kill counts back to 0
	for k, v in pairs(player.GetAll()) do
		v:SetFrags(0)
		v:SetHealth(100)
	end
	
	-- Setting PRDM state
	prdmState = true
	prdmRespawn()

	-- PRDM respawn
	timer.Create("RespawnTimer", 3, 9, function()
		prdmRespawn()
	end )
end )

hook.Add("TTTPrepareRound", "EndPRDM", function()
	
	-- Set PRDM state
	prdmState = false
	
	-- Make sure timers stop
	timer.Remove("RespawnTimer")
	
	-- Check kill counts and find winner
	for k, v in pairs(player.GetAll()) do
		if v:Frags() > prdmWinnerKC then
			prdmWinnerKC = v:Frags()
			prdmWinner = v:Name()
			prdmWinnerENT = v
		end
	end
	
	-- Print out winner and winner's kills
	timer.Simple(3, function()
		-- If winner got more than 1 kill
		if prdmWinnerKC > 1 then
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, prdmWinner .. " won ", WF_TC_WHITE, "PRDM with ", WF_TC_RED, prdmWinnerKC .. " kills", WF_TC_WHITE, "!")
			end
			--PrintMessage( HUD_PRINTTALK, prdmWinner .. " won PRDM with " .. prdmWinnerKC .. " kills!" )
		-- If winner only got 1 kill
		elseif prdmWinnerKC == 1 then
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, prdmWinner .. " won ", WF_TC_WHITE, "PRDM with ", WF_TC_RED, prdmWinnerKC .. " kill", WF_TC_WHITE, "!")
			end
			--PrintMessage( HUD_PRINTTALK, prdmWinner .. " won PRDM with " .. prdmWinnerKC .. " kill!" )
		-- If no one won PRDM
		else
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, "No one won ", WF_TC_WHITE, "PRDM!")
			end
			--PrintMessage( HUD_PRINTTALK, "No one won PRDM!" )
		end
		-- Give winner points. 1 kill = 25 points
		prdmWinnerENT:PS_Notify("You've been given ", (25 * prdmWinnerKC), " points for winning PRDM!")
		prdmWinnerENT:PS_GivePoints(25 * prdmWinnerKC)
	end )

end )

hook.Add("PlayerDeath", "PrintDeaths", function(victim, weapon, attacker)
	
	-- Check if PRDM and attacker and victim are players and valid
	if prdmState == true and IsValid(victim) and IsValid(attacker) and victim:IsPlayer() and attacker:IsPlayer() then
		
		-- Suicide
		if (victim == attacker) then
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, victim:Name(), WF_TC_WHITE, " commited suicide.")
			end
			--PrintMessage( HUD_PRINTTALK, victim:Name() .. " committed suicide." )
		-- Actual kill
		else
			for k, ply in pairs(player.GetAll()) do
				ply:PrintColor(WF_TC_RED, victim:Name(), WF_TC_WHITE, " was killed by ", WF_TC_RED, attacker:Name(), WF_TC_WHITE, ".")
			end
			--PrintMessage( HUD_PRINTTALK, victim:Name() .. " was killed by " .. attacker:Name() .. "." )
			-- Frag checker. Use if broken somehow
			--attacker:ChatPrint(attacker:Frags() + 1)
			attacker:AddFrags(1)
		end
		
	end
	
end )

function prdmRespawn()
	RunConsoleCommand("ulx", "csay", "It's post-round deathmatch time!")
		for k, v in pairs(player.GetAll()) do
			
			-- Intializing random weapon vars
			local randWepCategory = math.random(1,100)
			local randPistol = math.random(1,100)
			local randRifle = math.random(1,100)
			local randSpecial = math.random(1,100)
			local wepID = ""
			local wepName = ""
			
			-- Handling weapon IDs and names
			-- Category: Pistol
			if randWepCategory <= 45 then
				if randPistol <= 50 then
					-- Five-SeveN
					wepID = "pistol"
					wepName = "Five-SeveN"
				elseif randPistol > 50 and randPistol <= 75 then
					wepID = "magnum"
					wepName = "Magnum"
				elseif randPistol > 75 then
					-- Deagle
					wepID = "revolver"
					wepName = "Desert Eagle"
				end
			-- Category: Rifle/Shotgun
			elseif randWepCategory > 45 and randWepCategory <= 90 then
				if randRifle <= 10 then
					wepID = "m16"
					wepName = "M16"
				elseif randRifle > 10 and randRifle <= 20 then
					-- Scout
					wepID = "rifle"
					wepName = "Scout"
				elseif randRifle > 20 and randRifle <= 30 then
					wepID = "ak47"
					wepName = "AK47"
				elseif randRifle > 30 and randRifle <= 40 then
					wepID = "galil"
					wepName = "Galil"
				elseif randRifle > 40 and randRifle <= 50 then
					wepID = "famas"
					wepName = "Famas"
				elseif randRifle > 50 and randRifle <= 60 then
					wepID = "m3"
					wepName = "M3"
				elseif randRifle > 60 and randRifle <= 70 then
					wepID = "p90"
					wepName = "P90"
				elseif randRifle > 70 and randRifle <= 80 then
					wepID = "sg552"
					wepName = "SG552"
				elseif randRifle > 80 and randRifle <= 90 then
					-- XM1014
					wepID = "shotgun"
					wepName = "XM1014"
				elseif randRifle > 90 and randRifle <= 100 then
					-- HUGE
					wepID = "sledge"
					wepName = "useless piece of sh- I mean a H.U.G.E-249"
				end
			-- Category: Special
			else
				if randSpecial <= 30 then
					wepID = "awp"
					wepName = "AWP"
				elseif randSpecial > 30 and randSpecial <= 50 then
					wepID = "dragonsbreath"
					wepName = "Dragon's Breath"
				elseif randSpecial > 50 and randSpecial <= 80 then
					wepID = "medgun"
					wepName = "Med-Gun"
				elseif randSpecial > 80 then
					wepID = "jihad"
					wepName = "Bill- I mean a Jihad Bomb"
				end
			end
				
			-- PointShop perma weapon checker
			local permWepCount = v:PS_NumItemsEquippedFromCategory('Weapons')
			
			-- The actual respawn
			if !v:Alive() and IsValid(v) then
				-- Find corpse
				local corpse = corpse_find(v)
				if corpse then corpse_remove(corpse) end
				
				-- RESPAWN
				v:SpawnForRound()
				
				-- Give random weapon
				-- zm IDs
				if permWepCount == 0 then
					if wepID == "pistol" or wepID == "revolver" or wepID == "rifle" or wepID == "shotgun" or wepID == "sledge" then
						v:Give("weapon_zm_" .. wepID)
						v:SelectWeapon("weapon_zm_" .. wepID)
					-- ttt IDs
					else
						v:Give("weapon_ttt_" .. wepID)
						v:SelectWeapon("weapon_ttt_" .. wepID)
					end
					-- Print out weapon received
					v:PrintColor(WF_TC_WHITE, "You've been given a ", WF_TC_RED, wepName, WF_TC_WHITE, "!")
				end
			end
		end
end

end


Are there any errors or logs?

No, when the server crashes it doesn’t even restart on it’s own. The server console just stops printing out the normal stuff and doesn’t print out anything else.

Bump

Can anyone else take a look at it?