Hi, I am trying to make a GUI element teleport a player and I don’t really understand why it’s failing
local player = game.Players.LocalPlayer
script.Parent.MouseButton1Down:connect(function()
local hrp = player.Character.HumanoidRootPart
hrp.CFrame = game.Workspace.teleport.CFrame
end)
When the button is pressed, the console gives an error, “attempt to index character with nil”
I am sure the solution is quite obvious lol, I just can’t figure out how to get it working
Is your character actually loading? Or is CharacterAutoLoads off?
Also, I recommend saying
local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local hrp = character:WaitForChild("HumanoidRootPart")
script.Parent.MouseButton1Down:connect(function()
hrp.CFrame = game.Workspace.teleport.CFrame
end)