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

What's wong with my teleportation and wait script?

Asked by 10 years ago

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.

01if #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
07end
08 
09repeat wait() until #game.Players:GetPlayers() >2
10 
11target = CFrame.new(0, 5, -100) --could be near a brick or in a new area
12for i, player in ipairs(game.Players:GetChildren()) do
13    player.Character.Torso.CFrame = target + Vector3.new(0, i * 5, 0)
14    --add an offset of 5 for each character
15end

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.

1 answer

Log in to vote
1
Answered by
RedCombee 585 Moderation Voter
10 years ago

I would suggest using a loop to check instead of a one-time if statement.

01while 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
13end
Ad

Answer this question