Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Player Teleporting to some spots. Will they repeat?

Asked by 9 years ago

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!

2 answers

Log in to vote
3
Answered by 9 years ago

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.

Ad
Log in to vote
2
Answered by
DataStore 530 Moderation Voter
9 years ago

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

Answer this question