Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

I can't run the game in Studio because then Studio crashes. I think the script is crashing?

Asked by 9 years ago
01minigames = game.Lighting.Minigames:GetChildren()
02h = Instance.new("Hint", game.Workspace)
03 
04function removePlate()
05    local plates = game.Workspace.DisappearingPlates.Plates:GetChildren()
06    local ranNum1 = math.random(1,#plates)
07    local ranNum2 = 1
08    while ranNum1 == ranNum2 do
09    local ranNum2 = math.random(1,#plates)
10    wait(1)
11    end
12    local plateChosen = plates(ranNum1)
13    local plateChosen2 = plates(ranNum2)
14    for i = 0, 1, 0.06 do
15        plateChosen.Transparency = i
View all 69 lines...

1 answer

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
9 years ago

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.

01while true do
02    wait() --gotta have that
03    if game.Players.NumPlayers > 1 then
04        h.Text = "Deciding what game to play"
05        wait(3)
06        ranGame = math.random(1, #minigames)
07        gameChosen = minigames[ranGame]
08        h.Text = "Minigame chosen: " .. gameChosen.Name
09        wait(3)
10        gameChosenClone = gameChosen:Clone()
11        gameChosenClone.Parent = game.Workspace
12        wait(3)
13        --Teleporting players to map
14        spawns = gameChosenClone.Spawns:GetChildren()
15        for i,v in pairs(game.Players:GetPlayers()) do
View all 46 lines...
Ad

Answer this question