I wrote this script to teleport my character to a part (home) on a click of a button.
wait() char = script.Parent.Parent.Parent.Parent.Character script.Parent.MouseButton1Click:Connect(function() if char.Torso ~= nil then char.Torso.Cframe = workspace.home.CFrame elseif char.LowerTorso ~= nil then char.LowerTorso.CFrame = workspace.home.CFrame end end)
It seems like this doesn't work at all. I tried everything I know, including changing the code to change the position instead of the CFrame and changing the code to change the CFrame/position of the HumanoidRootPart.
Is there something that I'm missing here, or does this entire procedure work?
Try to teleport with HumanoidRootPart
and use variable to get player/char.
use local VARIABLE = ...
And you can simple use variable to get player, use :FindFirstChild("item")
not item ~= nil
Here is fixed script:
First method:
-- Removed the wait() local player = game.Players.LocalPlayer -- Get player local char = player.Character or player.CharacterAdded:Wait() -- Get Char script.Parent.MouseButton1Click:Connect(function() -- use HumanoidRootPart not LowerTorso, Torso if char:FindFirstChild("HumanoidRootPart") then char.HumanoidRootPart.CFrame = workspace.home.CFrame end end)
Second method:
-- (for me this method is better.) -- Removed the wait() local player = game.Players.LocalPlayer -- Get player local char = player.Character or player.CharacterAdded:Wait() -- Get Char script.Parent.MouseButton1Click:Connect(function() char:MoveTo(workspace.home.Position) end)
Wiki pages:
Hope it helped :D