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

How do you make a proper random player teleporter?

I have a script that doesn't work no matter how I code it. Can someone help me with this?

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

while true do
	randomPlayer.Character:MoveTo(Vector3.new(44.6,-13.5,-50.4))
	wait(3)
end

2 answers

I'm not really a fan of :MoveTo(). I prefer to edit their position manually. here's how I teleport players:

while true do
    randomPlayer.Character:SetPrimaryPartCFrame(CFrame.new(Vector3.new(44.6, -13.5, -50.4)))
    wait(3)
end

local randomPlayer = math.random(1, #players)

This will just return a number not the player

What you need is

while wait(3) do
	Player = game.Players:GetPlayers()
	selectedPlayer = Player[math.random(0, #Player)] 		  


workspace:WaitForChild(selectedPlayer.Name):SetPrimaryPartCFrame(CFrame.new(44.6, -13.5, 	-50.4)
end

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