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

Make 1 random player teleport/move?

Asked by 10 years ago

I only need ONE RANDOM player to be moved/teleported to a area instead of all players

while true do
wait()
for i,v in pairs(game.Players:GetChildren()) do
    v.Character:MoveTo(Vector3.new(-359.5, 291, 88.5))
end
wait(30)
end

2 answers

Log in to vote
0
Answered by
Perci1 4988 Trusted Moderation Voter Community Moderator
10 years ago

Well, to get a random player you need to get a random number. Then, since GetPlayers() returns a table, you can use that random number to get a player off of that table.

local players = game.Players:GetPlayers()
local randomNumber = math.random(1, #players)
local randomPlayer = players[randomNumber]

randomPlayer.Character:MoveTo(Vector3.new(-359.5, 291, 88.5))
0
do i replace randomNumber with a number or leave it as is Opptitronica 0 — 10y
0
I used math.random to get a random number. Perci1 4988 — 10y
Ad
Log in to vote
0
Answered by
ipiano 120
10 years ago

Try something like this:

while true do

    list = game.Players:GetChildren()
    victim = list[math.random(1, #list)]
    victim.Character.MoveTo(Vector3.new(-359.5, 291, 88.5))
    wait(30)

end

Answer this question