Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Cause of Roblox Studio Crashes?

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?

4 comments

0

Could you please put your code in lua format? :)

0

Edited for code block.

0

Oh yeah sorry wasn't in format should be fixed now.

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. :)

1 answer

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!

This discussion is preserved as it was. New answers, comments, and votes are closed.