I'm building a game which works in going around a circle and asking each one a question, and I'm teleporting people into the main room, but will this code teleport all 16 of them, or might it teleport someone twice or more times?
players = game.Players:GetChildren() players[math.random(1, #players)]:MoveTo(script.parent.part1.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part2.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part3.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part4.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part5.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part6.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part7.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part8.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part9.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part10.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part11.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part12.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part13.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part14.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part15.position) wait(.1) players[math.random(1, #players)]:MoveTo(script.parent.part16.position) wait(.1)
It's a bit repetitive, but if you can answer thank you!
The math.random use can be found here. Due to the circumstances, the chance of double teleportation is MUCH higher than no extra teleportations. To fix this try by using a randomizing technique which is shown on the link. After that use an iterator to go through the list and teleport the players.
It would more than likely teleport certain people more than once.
Use a generic for loop and ':GetPlayers()' instead.
for Num, Player in pairs(game.Players:GetPlayers()) do if Player.Character then --// Checking whether the player does actually have a character we can move. Player.Character:MoveTo(script.Parent["part" .. Num].Position) --// Moving the player to the numbered 'spawn' by concatenating the current iteration with 'part'. end end