|
| 08 Jul 2013 07:34 PM |
I'm trying to make a script that teleports all the players in a game to a location (100,100,100) and then 60 seconds later teleports them to (0,0,0). Here is what I have:
local players = game.Players:GetPlayers() for i = 1, #player do
player[i].Character:MoveTo(Vector3.new(100,100,100)) wait(60) player[i].Character:MoveTo(Vector3.new(0,0,0))
end
now the question: Will this script move one player to (100,100,100) wait 60 seconds move him back to (0,0,0) and then go to the next player move him to (100,100,100) and then back to (0,0,0) and so on for all the players.. or will it move all of the players to (100,100,100) and back to (0,0,0) after 60 seconds at once?
tl;dr: How can I make a script that teleports all players to (100,100,100) and then 60 seconds later back to (0,0,0)? |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2013 07:40 PM |
Instead of using coroutines, I'll just do this:
for _, Player in pairs(Game.Players:GetPlayers()) do if Player.Character then Player.Character:MoveTo(Vector3.new(100, 100, 100)) end end
wait(60)
for _, Player in pairs(Game.Players:GetPlayers()) do if Player.Character then Player.Character:MoveTo(Vector3.new(0, 0, 0)) end end |
|
|
| Report Abuse |
|
|
|
| 08 Jul 2013 07:42 PM |
use two loops, maybe for the sake of having this sorta thing a little more acessable and a little more dynamic, you could do it as a function.
Also, yours would have done each character on its own. What you need to do is do all of them at once, then wait 60 seconds, then run another loop to move them all back.
function MoveToThenBack(toPos, backPos, timeBetween) local Target = toPos or Vector3.new() local Origin = backPos or Vector3.new() local Time = timeBetween or 60
for _, player in pairs(game.Players:GetChildren()) do if player.Character then --make sure it has a character player.Character:MoveTo(Target) end end
wait(Time)
for _, player in pairs(game.Players:GetChildren()) do if player.Character then --make sure it has a character player.Character:MoveTo(Origin) end end end
Now to call the function for what you wanted, you just do this
MoveToThenBack(Vector3.new(100,100,100), Vector3.new(0, 0, 0), 60)
|
|
|
| Report Abuse |
|
|
| |
|