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

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

Asked by 9 years ago

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

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. iaz3 190 — 9y

1 answer

Log in to vote
0
Answered by
noliCAIKS 210 Moderation Voter
9 years ago

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
Ad

Answer this question