Place teleport not working

I’m using roblox’s module script for teleporting, but it’s saying “Invalid list of players for teleport.”

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")

local SafeTeleport = require(ServerScriptService.SafeTeleport)

local TARGET_PLACE_ID = 9671855606 -- replace with your own place ID

local playerToTeleport = Players:GetPlayers()[1] -- get the first player in the game

script.Parent.Touched:Connect(function(v)
	if v.Parent:FindFirstChildWhichIsA("Humanoid") then
		SafeTeleport(TARGET_PLACE_ID, {playerToTeleport})
	end
end)

Try:
{playerToTeleport.UserId}

Sorry I’m getting back so late, I completely forgot about this. I tried the UserId, but it said “variable playerToTeleport defined at line 8 is never initialized or assigned”.

can you print playerToTeleport?

I just did that right before reading this, but somehow it turned out nil? maybe the players:getplayers is wrong?

its because you’re getting the players/player when the server first starts try this

local playerToTeleport = Players:GetPlayers()
SafeTeleport(TARGET_PLACE_ID, {playerToTeleport[1]})
1 Like

Thanks, I put the playersToTeleport in the touched function, and it worked

1 Like