Teleport Script Not Working

Hello, so I have a GUI with ResetOnSpawn off. When I respawn, it doesn’t work.

Code:

local char = game.Players.LocalPlayer.Character -- if this doesnt work, use your own variables that targeting to Player


script.Parent.MouseButton1Click:Connect(function()
	char.Torso.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,3.25,0) -- Change Part1 to Your Teleport brick name
end)

Thanks!

Instead of using the Torso.CFrame try using the HumanoidRootPart.CFrame, create a variable under the variable “char”
local humRootPart = char:FindFirstChild("HumanoidRootPart").

local char = game.Players.LocalPlayer.Character
local humRootPart = char:FindFirstChild("HumanoidRootPart")

script.Parent.MouseButton1Click:Connect(function()
humRootPart.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,3.25,0)
end)

Because the gui is ResetOnSpawn and you define character only at run time whenever the character respawns you are still referencing the old character. What you can do is put the character variable inside the MouseButton1Click event.

script.Parent.MouseButton1Click:Connect(function()
    local char = game.Players.LocalPlayer.Character or game.Players.LocalPlayer.CharacterAdded:Wait() -- if this doesnt work, use your own variables that targeting to Player
	char.Torso.CFrame = game.Workspace.SpawnLocation.CFrame + Vector3.new(0,3.25,0) -- Change Part1 to Your Teleport brick name
end)
1 Like