Teleport Script Not working

Hi im trying to make a teleport script between areas the code doesnt seem to work Whats wrong with it
Its a local script
local Player = game.Players.LocalPlayer

local HumanoidRP = Player.Character:FindFirstChild(“HumanoidRootPart”)

local TeleportFolder = game.Workspace.Teleporters

TeleportFolder.Path1to2.Touched:Connect(function()

HumanoidRP.CFrame = TeleportFolder.Path1to2Reciver.CFrame

end)

You can’t get the local player on the server, and you need to pass through an argument in the touched to detect the player.

local TeleportFolder = game.Workspace.Teleporters 

TeleportFolder.Path1to2.Touched:Connect(function(hit) -- hit is the argument passed through, can be named anything
	if hit.Parent:FindFirstChild("Humanoid") then
		local Player = game.Players:GetPlayerFromCharacter(hit.Parent) -- GetPlayerFromCharacter
		local Char = Player.Character or Player.CharacterAdded:Wait()
		local HRP = Char:WaitForChild("HumanoidRootPart")
		
		HRP.CFrame = TeleportFolder.Path1to2Reciver.CFrame
	end
end)

API Reference - GetPlayerFromCharacter

3 Likes

You just have to wait for the Instances to replicate. Also add the debounce technique so it doesn’t have a weird effect. This code should be in a LocalScript in StarterGui or StarterPack to work properly.

local Player = game:GetService("Players").LocalPlayer
local character = Player.Character or Player.CharacterAdded:Wait()
local HumanoidRP = character:WaitForChild("HumanoidRootPart")

local TeleportFolder = workspace:WaitForChild("Teleporters")

local debounce = false
TeleportFolder:WaitForChild("Path1to2").Touched:Connect(function()
	if not debounce then
		debounce = true
		HumanoidRP.CFrame = TeleportFolder:WaitForChild("Path1to2Reciver").CFrame + Vector3.new(0, 3, 0)
		debounce = false
	end
end)