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

Can I make an automatic teleport script?

Asked by 4 years ago
Edited 4 years ago

Can anyone help me create an automatic teleport script? Example; 5 minutes pass - random player - transported to CFrame (-154) Sorry if the example is not explicit. The script literally chooses a random player within 7 minutes and that player is transported Imagine

local Players = game:GetService("Players")
local PlaceXYZ = Vector3.new(1, 0, 10)

function teleportRandomPlayer()
 local plrs = Players:GetChildren()
 local n = math.random(1, #plrs)
 for i, v in pairs(plrs) do
  if i == n then
   if workspace:FindFirstChild(v.Name) then
    if workspace[v.Name]:FindFirstChild("HumanoidRootPart") then
     workspace[v.Name].HumanoidRootPart.Position = PlaceXYZ
    end
   end
   break
  end
 end
end

spawn(function()
 while wait(1000) do
  teleportRandomPlayer()
 end
end)

I tried this script and it didn't work

0
Could you explain more? Ziffixture 6913 — 4y
0
sure the server automatically chooses a player and within 7 minutes the player is automatically teleports to a location andre_eds456 5 — 4y
0
Yes, I had this problem too. Basically, the baseplate moves instead of you. DangerousKillerTimur 54 — 4y

1 answer

Log in to vote
0
Answered by
SnowieDev 171
4 years ago
Edited 4 years ago

Teleports a healthy/alive random player every 7 minutes.

Put the code into a ServerScript, and then you can put the ServerScript into ServerScriptService or the workspace.

local PlayersService = game:GetService("Players")
local PlaceXYZ = CFrame.new(1, 0, 10)

function TeleportRandomPlayer()
    local Players = PlayersService:GetChildren()
    local Chosen = Players[math.random(#Players)]
    if game.Workspace:FindFirstChild(Chosen.Name) then
        local ChosenCharacter = game.Workspace:FindFirstChild(Chosen.Name)
        local ChosenHumanoid = ChosenCharacter:WaitForChild("Humanoid")
        if ChosenHumanoid.Health > 0 then
            local ChosenHumanoidRootPart = ChosenCharacter:WaitForChild("HumanoidRootPart")
            ChosenHumanoidRootPart.CFrame = PlaceXYZ
        end
    end
end

while wait(420) do
    TeleportRandomPlayer()
end
Ad

Answer this question