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?
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!