Hello, I have been working on a minigame script, and the game seems to work perfectly, but when enough people are playing it freezes at this part on the script randomly.
To summarize: The script can work with 20 people, but after awhile it randomly breaks displaying one of those texts as hints.
I'm not sure if it freezes because a player leaves the game or what. Can someone help me put a check in the script to prevent it from breaking? Any help would be really appreciated!
while cc < 2 do cc = 0 c = game.Players:GetChildren() for num, obj in pairs(c) do if obj:FindFirstChild("Playing") then if obj.Playing.Value then cc = cc + 1 end end end h.Text = "Need at least 2 players to begin games" wait(1) end h.Text = "New round will begin soon..." wait(3) h.Text = "Choosing random game..." wait(3) m = game.Lighting.Minigames:GetChildren() mg = m[math.random(1,#m)] map = mg.Map set_spawns(map) map.Parent = game.Workspace h.Text = (""..mg.Name) wait(5) h.Text = "Get ready to fight..." wait(2) c = game.Players:GetChildren()
So I'm going to assume this is the whole script. You are ending the while loop early, so once the script ends, it stops because it's not inside a loop. The script will run regardless of player count.
while true do --Note this loop has an "end" all the way at the end of the script. The script will keep repeating itself now. while cc < 2 do cc = 0 c = game.Players:GetChildren() for num, obj in pairs(c) do if obj:FindFirstChild("Playing") then if obj.Playing.Value then cc = cc + 1 end end end h.Text = "Need at least 2 players to begin games" wait(1) end h.Text = "New round will begin soon..." wait(3) h.Text = "Choosing random game..." wait(3) m = game.Lighting.Minigames:GetChildren() mg = m[math.random(1,#m)] map = mg.Map set_spawns(map) map.Parent = game.Workspace h.Text = (""..mg.Name) wait(5) h.Text = "Get ready to fight..." wait(2) c = game.Players:GetChildren() end