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

Cause of Roblox Studio Crashes?

Asked by
Vido01 5
8 years ago
local m = Instance.new("Message")
local h = Instance.new("Hint")

 while true do
    if game.Players.NumPlayers == 1 then
        wait(1)
        m.Text = "Loading-Please wait."
        wait(3)
        local Spawns1 = game.Workspace.Elevator.ElevatorSpawn:GetChildren()
        wait(1)
        local Spawns2 = game.Workspace.LobbySpawn:GetChildren()
        wait(1)
        m.Text = "Teleporting to Elevator"
        wait(1)
        for i, v in pairs(game.Players:GetPlayers()) do
            local name = v.Name
            local check = game.Workspace:FindFirstChild(name)
            if check then
                checkHumanoid = check:FindFirstChild("Humanoid")
                if checkHumanoid then
                    check:MoveTo(Spawns1[1].Position)
                    wait(5)
                end
            end
        end
    end
end

Every time I click "Play" the green bar at the bottom of ROBLOX Studio goes about halfway, then stops. It will sit there for about a minute and then come up with a pop-up that says: "Roblox Studio is not responding."

My game worked fine while I was working on other scripts, so I know that this one is causing it to crash. I'm not exactly sure why. I added waits in between the variables and functions but it doesn't help. Do I need to add waits in between the "ends" at the bottom?

0
Could you please put your code in lua format? :) TheeDeathCaster 2368 — 8y
0
Edited for code block. M39a9am3R 3210 — 8y
0
Oh yeah sorry wasn't in format should be fixed now. Vido01 5 — 8y
1
You should put a 'wait' in your 'while' loop: your problem is your first 'if' statement: if there're not '1' player(s) in your game, then it wont follow the following chunks: + Player assets doesn't load for a little bit. :) TheeDeathCaster 2368 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

As TheAlphaStigma said in the comments, you're not using a wait in your while loop.

Basically, what's happening is that the script runs before the player actually joins.

My hypothesis is that the server has to be made before the player can join... or something.

Anyways, a very easy wait to fix this it to throw a wait() in there.

local m = Instance.new("Message")
local h = Instance.new("Hint")

 while wait() do--Add a wait
    if game.Players.NumPlayers == 1 then
        wait(1)
        m.Text = "Loading-Please wait."
        wait(3)
        local Spawns1 = game.Workspace.Elevator.ElevatorSpawn:GetChildren()
        wait(1)
        local Spawns2 = game.Workspace.LobbySpawn:GetChildren()
        wait(1)
        m.Text = "Teleporting to Elevator"
        wait(1)
        for i, v in pairs(game.Players:GetPlayers()) do
            local name = v.Name
            local check = game.Workspace:FindFirstChild(name)
            if check then
                checkHumanoid = check:FindFirstChild("Humanoid")
                if checkHumanoid then
                    check:MoveTo(Spawns1[1].Position)
                    wait(5)
                end
            end
        end
    end
end

I would even suggest doing this to your while loops always, or almost always, for safety.

Good Luck!

Ad

Answer this question