So I have a script that makes an NPC walk back to a location after being pushed away too far, and he turns around to where he was facing initially, but every time the npc turns around, he starts floating, does anyone know the issue? here's the script.
local tws = game:GetService("TweenService")
local hrppos = Vector3.new(-98.342, 4.648, -41.35)
local hrport = Vector3.new(0, -67.5, 0)
local shoveCount = 0
local debounce = false
game:GetService("RunService").Stepped:Connect(function()
local magnitude = (hrppos - script.Parent.HumanoidRootPart.Position).magnitude
wait(.1)
if magnitude >= 5 then
script.Parent.Humanoid:MoveTo(hrppos)
local ort = {
Orientation = hrport;
}
repeat wait() until script.Parent.HumanoidRootPart.Velocity == Vector3.new(0,0,0)
if debounce == false then
debounce = true
local anim = tws:Create(script.Parent.HumanoidRootPart,TweenInfo.new(0.5,Enum.EasingStyle.Linear),ort)
anim:Play()
wait(.5)
shoveCount = shoveCount + 1
print(shoveCount)
if shoveCount > 0 then
local UI = script.Text:Clone()
UI.Parent = script.Parent.Head
if shoveCount == 1 then
UI.Frame.TextLabel.Text = "Oh, sorry!"
elseif shoveCount == 2 then
UI.Frame.TextLabel.Text = "..."
elseif shoveCount == 3 then
UI.Frame.TextLabel.Text = "Could you please stop\nshoving me around?"
elseif shoveCount == 4 then
UI.Frame.TextLabel.Text = "Quit it!"
elseif shoveCount >= 5 then
UI.Frame.TextLabel.Text = "????"
end
wait(2)
UI:Destroy()
debounce = false
end
end
end
end)
