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

How do I teleport ALL players in the server, to a spesific area?

Asked by 6 years ago

My friend asked this to me. He wants to teleport ALL players in the server, to a spesific area on the server. The following code that he has only teleports ONE player.

The code:

while true do
    wait(1) 
    local m = math.random(1,1) 
    local player = game.Players:GetPlayers()
    for i = 1, #player do
        msg = Instance.new("Message")
        msg.Parent = nil
        if m == 1 then
            msg.Parent = game.Workspace -- gets players
            wait(10)
            player[i].Character:MoveTo(Vector3.new(297.023, 41.105, 41.83))
            msg:remove()
            wait(60)

        end
        wait(5)
        player[i].Character:MoveTo(Vector3.new(-23.112, 101.5, 38.096))
        msg:remove()
    end
end
0
"msg.Parent = game.Workspace -- gets players" just wanna point this out SmugNyan 24 — 6y
0
do msg.Parent = game.Workspace to get the players creeperhunter76 554 — 6y
0
lol wtf how does line 9 get players beat you to it hiim Subaqueously 11 — 6y
0
okay......? hiimgoodpack 2009 — 6y

1 answer

Log in to vote
1
Answered by 6 years ago

What's wrong with your script is that it waits 70 seconds before teleporting each player. To fix this, you want to spawn a new thread.

while true do
    wait(1) 
    local m = math.random(1,1) 
    local player = game.Players:GetPlayers()
    for i = 1, #player do
        msg = Instance.new("Message")
        msg.Parent = nil
        if m == 1 then
            spawn(function()
            msg.Parent = game.Workspace -- gets players
                wait(10)
                player[i].Character:MoveTo(Vector3.new(297.023, 41.105, 41.83))
                msg:remove()
             wait(60)
        end)
        end
        wait(5)
        player[i].Character:MoveTo(Vector3.new(-23.112, 101.5, 38.096))
        msg:remove()
    end
end

0
But don't spawn threads yield when you call wait()? hiimgoodpack 2009 — 6y
0
the `for` loop won't yield creeperhunter76 554 — 6y
0
no it would since you put wait() in it. wait() is a yield function. hiimgoodpack 2009 — 6y
Ad

Answer this question