I’m making an npc touch you and teleport behind you but every time he touches me, no matter how far away, he always teleports to that place and I don’t know how to fix it.
my code here:
local humanoidNPC = script.Parent.Parent.Humanoid
local hrp = script.Parent.Parent.HumanoidRootPart
script.Parent.Touched:Connect(function(hit)
local humanoid = hit.Parent:FindFirstChild("Humanoid")
local torso = hit.Parent:FindFirstChild("LowerTorso")
if humanoid ~= nil and deb == false then
deb = true
humanoidNPC.WalkSpeed = 0
humanoid.WalkSpeed = 0
hrp.CFrame = CFrame.new(Vector3.new(torso.Position))
print("Works!!!")
wait(3)
humanoid.WalkSpeed = 16
humanoidNPC.WalkSpeed = 20
deb = false
end
end)