Script to stick a player to an NPC not working

This code is supposed to make a player stick to a npc (Follow its position)
But when I use printing for an error it ends at this line.
Positioning

LocalPlayer.HumanoidRootPart.Position = Npc.HumanoidRootPart.Position

full script


local button = script.Parent
print("Test")
local Npc = game.workspace.Npc
print("Test")
local LocalPlayer = game.Players.LocalPlayer
print("Test")
local sticking = LocalPlayer.HumanoidRootPart.Position
print("Test")
function onClick(Click)
	print("Test")
	wait(10)
	print("Test")
	LocalPlayer.HumanoidRootPart.Position = Npc.HumanoidRootPart.Position
	print("Test")
end
print("Test")
button.MouseButton1Click:Connect(onClick)
print("Worked!")
1 Like

that isn’t how it works
it goes like this

LocalPlayer.Character.HumanoidRootPart.Position

I doubt Character even exists when this code runs so you can do

local Character = LocalPlayer.Character or LocalPlayer.CharacterAdded:Wait()
local sticking = Character.HumanoidRootPart.Position
1 Like

Worked but now stops at function.

What do you mean by that? Can you elaborate?

I mean the player Sticks onto the npc. (Where ever the npc walks the player follows it’s position unless they hit the close button)

the printing stops here

function onClick(Click)
	print("Test")
	wait(10)
	print("Test")
	LocalPlayer.HumanoidRootPart.Position = Npc.HumanoidRootPart.Position
	print("Test")
end
print("Test")
button.MouseButton1Click:Connect(onClick)
print("Worked!")

You didn’t change the LocalPlayer.Humanoid portion of your code…