minigames = game.Lighting.Minigames:GetChildren() h = Instance.new("Hint", game.Workspace) function removePlate() local plates = game.Workspace.DisappearingPlates.Plates:GetChildren() local ranNum1 = math.random(1,#plates) local ranNum2 = 1 while ranNum1 == ranNum2 do local ranNum2 = math.random(1,#plates) wait(1) end local plateChosen = plates(ranNum1) local plateChosen2 = plates(ranNum2) for i = 0, 1, 0.06 do plateChosen.Transparency = i plateChosen2.Transparency = i wait() end plateChosen:Destroy() plateChosen2:Destroy() end while true do if game.Players.NumPlayers > 1 then h.Text = "Deciding what game to play" wait(3) ranGame = math.random(1, #minigames) gameChosen = minigames[ranGame] h.Text = "Minigame chosen: " .. gameChosen.Name wait(3) gameChosenClone = gameChosen:Clone() gameChosenClone.Parent = game.Workspace wait(3) --Teleporting players to map spawns = gameChosenClone.Spawns:GetChildren() for i,v in pairs(game.Players:GetPlayers()) do name = v.Name check = game.Workspace:FindFirstChild(name) if check then checkHumanoid = check:FindFirstChild("Humanoid") if checkHumanoid then v.Character:MoveTo(spawns[i].Position) end end end for i = 3, 1, -1 do h.Text = "Game begins in: " .. i wait(1) end if gameChosenClone.Name == "DisappearingPlates" then timeTillGameEnds = 20 --Countdown until the game ends for i = timeTillGameEnds, 1, -1 do h.Text = "Time Left: " .. i removePlate() end else h.Text = "There needs to be more than 1 player to start" wait(1) end end end
while
loops must contain some sort of delay, otherwise they will crash the server. Usually this delay is the wait()
function.
Your loop contains several of these functions, but notice that they're all inside of your first if
statement! This means that if your if
statement is false, your script will never wait, and thus crash.
Just add a small delay every time it loops, no matter the outcome of the if
statement.
while true do wait() --gotta have that if game.Players.NumPlayers > 1 then h.Text = "Deciding what game to play" wait(3) ranGame = math.random(1, #minigames) gameChosen = minigames[ranGame] h.Text = "Minigame chosen: " .. gameChosen.Name wait(3) gameChosenClone = gameChosen:Clone() gameChosenClone.Parent = game.Workspace wait(3) --Teleporting players to map spawns = gameChosenClone.Spawns:GetChildren() for i,v in pairs(game.Players:GetPlayers()) do name = v.Name check = game.Workspace:FindFirstChild(name) if check then checkHumanoid = check:FindFirstChild("Humanoid") if checkHumanoid then v.Character:MoveTo(spawns[i].Position) end end end for i = 3, 1, -1 do h.Text = "Game begins in: " .. i wait(1) end if gameChosenClone.Name == "DisappearingPlates" then timeTillGameEnds = 20 --Countdown until the game ends for i = timeTillGameEnds, 1, -1 do h.Text = "Time Left: " .. i removePlate() end else h.Text = "There needs to be more than 1 player to start" wait(1) end end end