Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

What am I doing wrong with selecting 1 player and teleporting him??

This script is supposed to get 1 random player out of the players service and teleport him when he/ she is chosen.

players = game.Players:GetChildren()

while true do wait() playerchose = math.random(1,#players) playerchosen = players[playerchose] playerchosen.Character.Torso.CFrame = CFrame.new(Vector3.new(10,10,10)) wait(2) end end

1 comment

0

Put your code in a code block. Provide details as to WHAT the error is. If no output is given by studio, tell us.

1 answer

You have two ends at the end. If you remove one of them it should work. Make sure to check if there is at least one player though, otherwise it might error. With that check in there, you do need two ends after all.

players = game.Players:GetChildren()

while true do
wait()
if #players > 0 then
playerchose = math.random(1,#players)
playerchosen = players[playerchose]
playerchosen.Character.Torso.CFrame = CFrame.new(Vector3.new(10,10,10))
wait(2)
end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.