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

Why Sometimes A Command would loop, Or Maps Won't Load?

Asked by 5 years ago

If I Like Restart Sometimes: The Command Just Loops or Maps Don't Load?

I'm Having A Different Problem Everytime I Reset Server, Help Please. Have I Done Something Wrong with End statments?

local s = script.Stat

---------------------------------------

---------------INTERMISSION-----------------------

t = 0

while true do
    t= 8
    repeat
        t= t-1
        s.Value = "Next Game Starting in "..t
        wait(1)
    until t == 0
    -------------------- TELEPORT THEM TO GAME------------
    game.Workspace.Gravity = 30

    local Maps = {'Forest','Lava','ToxicGas','Laser','Ice'}
    local randomMap = math.random(1, #Maps)
    for i,v in pairs(Maps) do
        if randomMap == i then
        local storage = game:GetService("ReplicatedStorage")
        local map = storage.Maps:WaitForChild(v):Clone()
    map.Parent = workspace.MapPlaying

wait(1)

target = CFrame.new(137, 190.5, 188)
for i, player in pairs(game.Players:GetChildren()) do
    player.Character.UpperTorso.CFrame = target
end
end

-------------------------------------------
t = 5
repeat
    t= t-1
    s.Value = "Dropping Down In "..t 
    wait(1)
until t == 0
game.Workspace.Game.Roof.CanCollide = false
game.Workspace.Game.Roof.Transparency = 1
end

t = 10
repeat
    t= t-1
    s.Value = t.." Seconds Left To Complete Level"
    wait(1)
until t == 0

target = CFrame.new(-250, 2.19, 158)
for i, player in pairs(game.Players:GetChildren()) do
    player.Character.UpperTorso.CFrame = target
    --add an offset of 5 for each character
end


game.Workspace.Gravity = 180

game.Workspace.MapPlaying:ClearAllChildren()

--------------------- Teleport Players To LOBBY-------------
game.Workspace.Game.Roof.CanCollide = true
    game.Workspace.Game.Roof.Transparency = 0.6

    wait(1)


    s.Value = "Game Ended"
    end
    ---------------- RESTORE------------------

wait(4)

1 answer

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

Hey, ItzJester2. I tested out your script and it seems like your "Dropping down" repeat loop keeps repeating regardless of correct logic. Instead I replaced it with a simple for loop, which made it work and not repeat anymore. Also, YES. You did mess up the ends and I corrected that. Just copy this script down below and replace it with your old one

Make sure to upvote and accept this answer. Thanks!

local s = script.Stat

---------------------------------------

---------------INTERMISSION-----------------------

t = 0

while true do
    t= 8
    repeat
        t= t-1
        s.Value = "Next Game Starting in "..t
        wait(1)
        print(t)
    until t == 0
    -------------------- TELEPORT THEM TO GAME------------
    game.Workspace.Gravity = 30

    local Maps = {'Forest','Lava','ToxicGas','Laser','Ice'}
    local randomMap = math.random(1, #Maps)
    for i,v in pairs(Maps) do
        if randomMap == i then
        local storage = game:GetService("ReplicatedStorage")
        local map = storage.Maps:WaitForChild(v):Clone()
        map.Parent = workspace.MapPlaying
        end
    end

wait(1)

    target = CFrame.new(137, 190.5, 188)
    for i, player in pairs(game.Players:GetChildren()) do
        player.Character.Torso.CFrame = target
    end

-------------------------------------------
t = 5
for i = 5, 1, -1 do
    t = t - 1
    s.Value = "Dropping Down In " .. t
    wait(1)
end
game.Workspace.Game.Roof.CanCollide = false
game.Workspace.Game.Roof.Transparency = 1
t = 10
repeat
    t= t-1
    s.Value = t.." Seconds Left To Complete Level"
    wait(1)
until t == 0

target = CFrame.new(-250, 2.19, 158)
for i, player in pairs(game.Players:GetChildren()) do
    player.Character.Torso.CFrame = target
    --add an offset of 5 for each character
end


game.Workspace.Gravity = 180

game.Workspace.MapPlaying:ClearAllChildren()

--------------------- Teleport Players To LOBBY-------------
game.Workspace.Game.Roof.CanCollide = true
    game.Workspace.Game.Roof.Transparency = 0.6

    wait(1)


    s.Value = "Game Ended"
end
    ---------------- RESTORE------------------

wait(4)
0
Thank You So Much, Can You Tell Me When I Have To Place The Ends? ItzJester2 12 — 5y
0
Well first you should learn how to tab correctly. Google it. Your end placement should always be on the same column as the function/loop/if that your ending with. In other words, for each function, while loop, for loop, and if statement, you need an 'end' to it. laughablehaha 494 — 5y
0
Well first you should learn how to tab correctly. Google it. Your end placement should always be on the same column as the function/loop/if that your ending with. In other words, for each function, while loop, for loop, and if statement, you need an 'end' to it. laughablehaha 494 — 5y
Ad

Answer this question