I made a script that's supposed to teleport players to a location AFTER there are at least two players in the server. The script is a local script inside StarterPack. The code is below.
01 | if #Players:GetChildren() < 2 then |
02 | local m = Instance.new( "Message" , game.Workspace) |
03 | m.Text = "There must be 2 or more players in the server." |
04 | if #game.Players:GetPlayers() > = 2 then |
05 | m:Destroy() |
06 | end |
07 | end |
08 |
09 | repeat wait() until #game.Players:GetPlayers() > 2 |
10 |
11 | target = CFrame.new( 0 , 5 , - 100 ) --could be near a brick or in a new area |
12 | for i, player in ipairs (game.Players:GetChildren()) do |
13 | player.Character.Torso.CFrame = target + Vector 3. new( 0 , i * 5 , 0 ) |
14 | --add an offset of 5 for each character |
15 | end |
While the server is waiting for the # of players to be >= 2, a message is supposed to be displayed across the screen. The message won't appear, and I'm not sure what to do. Any help is appreciated.
I would suggest using a loop to check instead of a one-time if statement.
01 | while wait( 1 ) do |
02 | if #game.Players:GetChildren() < 2 then |
03 | if not game.Workspace:FindFirstChild( "PMessage" ) then |
04 | local m = Instance.new( "Message" ,game.Workspace) |
05 | m.Name = "PMessage" |
06 | m.Text = "There must be 2 or more players in the server." |
07 | end |
08 | elseif #game.Players:GetChildren() > = 2 then |
09 | if game.Workspace:FindFirstChild( "PMessage" ) then |
10 | game.Workspace.PMessage:Remove() |
11 | -- Rest of code to start the game here |
12 | end |
13 | end |