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

Teleport to a random player?

Asked by
Seenit 80
10 years ago

This script doesnt have the teleport (which is just CFrame) but I'd like to know if Im doing this right

a=game.Players:GetChildren()
target = Vector3.new(math.random(1,#a).Character.Torso.Position)

1 answer

Log in to vote
1
Answered by 10 years ago

With a, you should use :GetPlayers(). This creates a table of the players.

math.random(1, #a).Character.Torso.Position

If math.random(1, #a) returned 5, this would tell the script:

5.Character.Torso.Position

That doesn't even make sense. What is 5? 5 has a Character? To get the 5th value in the table of the players, you would do a[5]. This would retrieve the value, which would be the Player. Therefore, you need to have this as:

a[math.random(1, #a)].Character.Torso.Position

You do not need to put it in a Vector3, as Position already is a Vector3.

Otherwise, it seems like you've ran all the bases.

Ad

Answer this question