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

Can I make an automatic teleport script?

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

3 comments

0

Could you explain more?

0

sure the server automatically chooses a player and within 7 minutes the player is automatically teleports to a location

0

Yes, I had this problem too. Basically, the baseplate moves instead of you.

1 answer

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

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