So my game is a zombie survival game where the player survives and goes to the next wave, everything works fine solo but when someone joins or leaves it stops the repeat loop and breaks everything, am so confused, please help!
This shows the wave stopping and not doing the loop of going to the next wave. Is this error causing my game to break?
line 101 is
v.Character:MoveTo(spawns[i].Position)
local roundMsg = game.ReplicatedStorage.Values:WaitForChild("roundMsg")
local zombieCount = game.ReplicatedStorage.Values:WaitForChild("zombiesRemaining")
local zombiesAlive = game.ReplicatedStorage.Values:WaitForChild("zombiesAlive")
local gameInProgress = game.ReplicatedStorage.Values:WaitForChild("gameInProgress")
local wave = game.ReplicatedStorage.Values:WaitForChild("Wave")
local collectionservice = game:GetService("CollectionService")
local Complete = game.Workspace["Level Complete"]
Maps = game.ServerStorage.Maps:GetChildren()
game.Players.PlayerRemoving:Connect(function(player)
collectionservice:AddTag(player.Character, "Dead")
end)
while true do
roundMsg.Value = "Waiting for enough players"
repeat wait(1) until game.Players.NumPlayers >= 1
for i = 10,0,-1 do
roundMsg.Value = "Game Starting in: "..i
if i == 1 then
roundMsg.Value = "Choosing map..."
wait(2)
ranGame = math.random(1, #Maps)
gameChosen = Maps[ranGame]
roundMsg.Value = "Map chosen: " .. gameChosen.Name
wait(2)
gameChosenClone = gameChosen:Clone()
gameChosenClone.Parent = workspace.Map
wait(2)
for i, v in pairs(workspace.Map:FindFirstChildOfClass("Model"):GetChildren()) do
if v.Name == "Spawner" then
collectionservice:AddTag(v, "Spawner")
end
end
wait()
spawns = gameChosenClone.Spawns:GetChildren()
wait()
for i, v in pairs(game.Players:GetPlayers()) do
name = v.Name
wait()
check = game.Workspace:FindFirstChild(name)
if check then
checkHumanoid = check:findFirstChild("Humanoid")
wait()
if checkHumanoid then
wait()
v.Character:MoveTo(spawns[i].Position)
wait()
collectionservice:AddTag(v.Character, "Alive")
end
end
end
roundMsg.Value = "Game In Progress"
zombieCount.Value = 6
zombiesAlive.Value = 6
wave.Value = 1
gameInProgress.Value = true
repeat
game.Players.PlayerRemoving:Connect(function(player)
wait()
collectionservice:AddTag(player.Character, "Dead")
end)
if #collectionservice:GetTagged("Alive") > 0 then
wait()
if zombiesAlive.Value == 0 then
for i, v in pairs(workspace.Map:GetDescendants()) do
wait()
if v.Name == "ZED" then
wait()
collectionservice:AddTag(v, "ZED")
wait()
v:Destroy()
end
end
wave.Value = wave.Value + 1
Complete:Play()
wait(2)
zombieCount.Value = 6 * wave.Value
zombiesAlive.Value = 6 * wave.Value
for i, v in pairs(game.Players:GetPlayers()) do
wait()
collectionservice:AddTag(v.Character, "Alive")
wait()
name = v.Name
wait()
check = game.Workspace:FindFirstChild(name)
wait()
if check then
wait()
checkHumanoid = check:findFirstChild("Humanoid")
wait()
if checkHumanoid then
wait()
v.Character:MoveTo(spawns[i].Position)
wait()
end
end
end
end
elseif #collectionservice:GetTagged("Alive") == 0 then
wait()
gameInProgress = false
end
wait(1)
until gameInProgress == false or #collectionservice:GetTagged("Alive") == 0
wait()
for i, player in pairs(game.Players:GetPlayers()) do
wait(1)
player:LoadCharacter()
wait()
end
wait()
gameChosenClone:Destroy()
end
wait(1)
end
end