Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

4 comments

0

"msg.Parent = game.Workspace -- gets players" just wanna point this out

0

do msg.Parent = game.Workspace to get the players

0

lol wtf how does line 9 get players beat you to it hiim

0

okay......?

1 answer

✓ Accepted answer

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

3 comments

0

But don't spawn threads yield when you call wait()?

0

the for loop won't yield

0

no it would since you put wait() in it. wait() is a yield function.

This discussion is preserved as it was. New answers, comments, and votes are closed.