I want to teleport the players to many different locations after each other, but how can I achieve this?
for i, v in pairs(workspace.TeleportParts:GetChildren()) do
game.Players.LocalPlayer.Character.PrimaryPart.CFrame = v.CFrame
end
I want to teleport the players to many different locations after each other, but how can I achieve this?
for i, v in pairs(workspace.TeleportParts:GetChildren()) do
game.Players.LocalPlayer.Character.PrimaryPart.CFrame = v.CFrame
end
a loop is like wait
when the loop ends it will continue the next code at the end of the loop
for i = 1, 3 do
wait(1)
end
print("loop is finished")
you must do this on the server
cuz on the client you wont be able to know if other client is already teleported
you will need to send it to the server and send a delay to each client when they are ready to teleport which is more complicated
i think this is what you want to archive
local TeleportParts = workspace.TeleportParts:GetChildren()
for _, Player in pairs(game.Players:GetPlayers()) do
Player.Character.PrimaryPart.CFrame = TeleportParts[math.random(1, #TeleportParts)].CFrame
wait()
end
print("All Players Are Teleported!")
Code that you want to run after the for loop can be put directly after the loop
for i, v in pairs() do
wait(0.25)
end
print("Loop finished")
For loop will yield the script until the loop is finished and will only run the next line after finished looping
local start = tick()
for i = 1, 5 do
print("I'm still in the loop!")
task.wait(1)
end
print("Finished!")
print('That took '..tick()-start) -- approx. 5