01 | local m = Instance.new( "Message" ) |
02 | local h = Instance.new( "Hint" ) |
03 |
04 | while true do |
05 | if game.Players.NumPlayers = = 1 then |
06 | wait( 1 ) |
07 | m.Text = "Loading-Please wait." |
08 | wait( 3 ) |
09 | local Spawns 1 = game.Workspace.Elevator.ElevatorSpawn:GetChildren() |
10 | wait( 1 ) |
11 | local Spawns 2 = game.Workspace.LobbySpawn:GetChildren() |
12 | wait( 1 ) |
13 | m.Text = "Teleporting to Elevator" |
14 | wait( 1 ) |
15 | for i, v in pairs (game.Players:GetPlayers()) do |
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.
01 | local m = Instance.new( "Message" ) |
02 | local h = Instance.new( "Hint" ) |
03 |
04 | while wait() do --Add a wait |
05 | if game.Players.NumPlayers = = 1 then |
06 | wait( 1 ) |
07 | m.Text = "Loading-Please wait." |
08 | wait( 3 ) |
09 | local Spawns 1 = game.Workspace.Elevator.ElevatorSpawn:GetChildren() |
10 | wait( 1 ) |
11 | local Spawns 2 = game.Workspace.LobbySpawn:GetChildren() |
12 | wait( 1 ) |
13 | m.Text = "Teleporting to Elevator" |
14 | wait( 1 ) |
15 | for i, v in pairs (game.Players:GetPlayers()) do |
I would even suggest doing this to your while loops always, or almost always, for safety.
Good Luck!