generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

Looping through all the players with a delay.

Previous Thread :: Next Thread 
MangoPlant is online. MangoPlant
Joined: 29 Dec 2011
Total Posts: 65
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
CodyTheBuildingKid is not online. CodyTheBuildingKid
Joined: 13 Dec 2011
Total Posts: 4399
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
WhoBloxedWho is not online. WhoBloxedWho
Joined: 25 Mar 2009
Total Posts: 4611
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
MangoPlant is online. MangoPlant
Joined: 29 Dec 2011
Total Posts: 65
08 Jul 2013 07:53 PM
Great. Thanks both!
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image