Rounds not working

I am currently trying to start a single player zombie survival game, but I’m having an issue with the round system. Basically what’s supposed to happen is that each round begins and has a set amount of time in each round then after the round ends, if the player survives, the player receives one win and it goes into intermission. The problem is that the player doesn’t get any wins when completing a round and now the round system broke after I made the player’s character have to be manually spawned in.

Code:

--//variables
local RS = game:GetService("ReplicatedStorage")
local round = RS:WaitForChild("round").Value
local zombs = RS:WaitForChild("Dummies")
local event = RS:WaitForChild("roundEvent")
local deathMsg = RS:WaitForChild("deathMsg")
local startTime = 30
local players = game:GetService("Players")
local interlude = 20
local dumNum = RS:WaitForChild("dumNum").Value
local inRound = false
local match = true
local RF = game:GetService("ReplicatedFirst")

players.PlayerAdded:Connect(function(plr)
	local gui = plr:WaitForChild("PlayerGui")
	local UI = RF.MainUI:Clone()
	
	UI.Parent = gui
	--//spawning the player
	RS.spawnPlr.OnServerEvent:Connect(function(plr)
		plr:LoadCharacter()
	end)
	
	
	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local wins = plr.leaderstats:WaitForChild("Wins").Value
		
		--//starting game
		while hum.Health ~= 0 and match == true and plr:HasAppearanceLoaded() do
			task.wait(interlude)
			
			round += 1
			event:FireAllClients(round)
			
			--//spawns in zombies
			for i = 0, dumNum-1, 1 do
				local clone = zombs.Dummy:Clone()
				clone.Parent = game.Workspace.Peds
				local rand = math.random(1, 5)

				if round >= 15 then
					local tanky = zombs.Tanky:Clone()

					if rand == 3 then
						tanky.Parent = game.Workspace.Peds
						clone:Destroy()
					end
				elseif round >= 5 then
					local speedy = zombs.Speedy:Clone()
					
					if rand == 1 then
						speedy.Parent = game.Workspace.Peds
						clone:Destroy()
					end
				end
				
				
			end
			
			--//makes player in round and increases amount of zombies for next round
			inRound = true
			dumNum += 5
			
			--//checks if player has died since it has begun
			if hum.Health == 0 then				
				match = false
				inRound = false
				break
			end
			
			
			if inRound == true then
				--//checks again if player has died during round
				if hum.Health == 0 then				
					match = false
					inRound = false
					break
				end
				task.wait(startTime)
				
				--//increases amount of time per round and wins
				startTime += 15
				wins += 1
				
				inRound = false
			end
		end
	end)
end)

Thanks,
dza

1 Like

Connect the RemoteEvent outside the .PlayerAdded function. You also were changing the win value wrong. You were setting a variable that stored the win value, not the actual win value.

Code:

--//variables
local RS = game:GetService("ReplicatedStorage")
local round = RS:WaitForChild("round").Value
local zombs = RS:WaitForChild("Dummies")
local event = RS:WaitForChild("roundEvent")
local deathMsg = RS:WaitForChild("deathMsg")
local startTime = 30
local players = game:GetService("Players")
local interlude = 20
local dumNum = RS:WaitForChild("dumNum").Value
local inRound = false
local match = true
local RF = game:GetService("ReplicatedFirst")

players.PlayerAdded:Connect(function(plr)
	local gui = plr:WaitForChild("PlayerGui")
	
	local UI = RF.MainUI:Clone()
	UI.Parent = gui

	plr.CharacterAdded:Connect(function(char)
		local hum = char:WaitForChild("Humanoid")
		local wins = plr.leaderstats:WaitForChild("Wins")

		--//starting game
		while hum.Health ~= 0 and match == true and plr:HasAppearanceLoaded() do
			task.wait(interlude)

			round += 1
			event:FireAllClients(round)

			--//spawns in zombies
			for i = 0, dumNum-1, 1 do
				local clone = zombs.Dummy:Clone()
				clone.Parent = game.Workspace.Peds
				local rand = math.random(1, 5)

				if round >= 15 then
					local tanky = zombs.Tanky:Clone()

					if rand == 3 then
						tanky.Parent = game.Workspace.Peds
						clone:Destroy()
					end
				elseif round >= 5 then
					local speedy = zombs.Speedy:Clone()

					if rand == 1 then
						speedy.Parent = game.Workspace.Peds
						clone:Destroy()
					end
				end
			end

			--//makes player in round and increases amount of zombies for next round
			inRound = true
			dumNum += 5

			--//checks if player has died since it has begun
			if hum.Health == 0 then				
				match = false
				inRound = false
				break
			end


			if inRound == true then
				--//checks again if player has died during round
				if hum.Health == 0 then				
					match = false
					inRound = false
					break
				end
				task.wait(startTime)

				--//increases amount of time per round and wins
				startTime += 15
				wins.Value += 1

				inRound = false
			end
		end
	end)
end)

--//spawning the player
RS.spawnPlr.OnServerEvent:Connect(function(plr)
	plr:LoadCharacter()
end)

Also, I’m not very sure of why you are making the round start based on when one character respawns.

I changed the code, it looks like the while loop isn’t actually running so I’m not entirely sure what’s wrong.

figured out i actually needed to check if the player’s appearance loaded during the while loop otherwise it would only check once, causing an infinite wait

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.