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

How do you make a proper random player teleporter?

Asked by 5 years ago
Edited 5 years ago

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

Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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
Ad
Log in to vote
0
Answered by 5 years ago
Edited 5 years ago

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

Answer this question