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

Script breaks after about 30 minutes??

Asked by 10 years ago

I have a round script, it 's a loop while wait() do, and inside that loop if checks if there are more than 1 players, 2 if statements, if there are more than 1, then it does the round. It breaks after about 30 minutes, stuck on "Round in Progress", is there anything particular in this script that could make it break easier, or just that it's a loop? I know most round-based games don't break this easily.

while wait() do
    if game.Players.NumPlayers > 1 then
            wait(5)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Starting New Round..."

            wait(3)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Spawning Players..."

            wait(1)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round in Progress"

            for i,v in pairs(game.Players:GetPlayers()) do
            local coordinates = {Vector3.new(-80.9, 3.2, -286.5), Vector3.new(1.64, 3.2, -179.7), Vector3.new(83.5, 3.2, -287.5), Vector3.new(2.44, 3.2, -396.5)} 
            local randomCoor = coordinates[math.random(#coordinates)]
            local knife = game.ServerStorage.Knife:Clone()
            v.Character:MoveTo(randomCoor)
            knife.Parent = v.Backpack
            wait(0.3)
            end


            for i,v in pairs(game.Players:GetPlayers()) do
                v.Character.Torso.Anchored = true
                v.PlayerGui.countdownonspawn.Frame.Visible = true
                v.PlayerGui.countdownonspawn.three.Visible = true
            end
            wait(1)         
            for i,v in pairs(game.Players:GetPlayers()) do
                v.PlayerGui.countdownonspawn.three.Visible = false
                v.PlayerGui.countdownonspawn.two.Visible = true
            end
            wait(1) 
            for i,v in pairs(game.Players:GetPlayers())do
                v.PlayerGui.countdownonspawn.two.Visible = false
                v.PlayerGui.countdownonspawn.one.Visible = true
            end     
            wait(1)
            for i,v in pairs(game.Players:GetPlayers()) do
            v.PlayerGui.countdownonspawn.one.Visible = false
            v.PlayerGui.countdownonspawn.Frame.Visible = false
            v.Character.Torso.Anchored = false
            end

            for i,v in pairs(game.Players:GetPlayers()) do
                v.CameraMode = "LockFirstPerson"
            end

            local song = {game.Workspace.powerglove, game.Workspace.robotrock, game.Workspace.gunfinga, game.Workspace.firehive}
            local randomSong = song[math.random(#song)]
            randomSong:Play()
            wait(60)
            game.Workspace.powerglove:Stop()
            game.Workspace.robotrock:Stop()
            game.Workspace.gunfinga:Stop()
            game.Workspace.firehive:Stop()

            for i, v in pairs(game.Players:GetChildren()) do 
            v.CameraMode = "Classic"
            wait(0.3)
            v.Character.Humanoid.Health = 0
            end

            wait(5)

            game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "Round Finished!"

            end

    if game.Players.NumPlayers < 2 then
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players"
        wait(1)
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players."
        wait(1)
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players.."
        wait(1)
        game.Workspace.lobby.timer.SurfaceGui.timelft.Text = "This game requires 2+ Players..."
        wait(1)
    end
end


If there's something that's making it break easier please tell me.

2 answers

Log in to vote
0
Answered by
1waffle1 2908 Trusted Badge of Merit Moderation Voter Community Moderator
10 years ago

The script will break permanently if you try to index an object that isn't there, such as Torso, PlayerGui, Humanoid; these are all things that could potentially be missing, and if they are, the script will break. Either add an if statement to check if they are all there, or put the block in a pcall to ignore any errors.

0
Could I use WaitForChild("")? systematicaddict 295 — 10y
0
That won't work if it is never going to be there, like when a character dies or a player leaves. 1waffle1 2908 — 10y
Ad
Log in to vote
0
Answered by 10 years ago

You should then check if the object is there:

if workspace:FindFirstChild("Object") then
print('object is found in workspace!')
end

Answer this question