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

Make 1 random player teleport/move?

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

✓ Accepted answer

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))

2 comments

0

do i replace randomNumber with a number or leave it as is

0

I used math.random to get a random number.

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

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