Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to stop NPC from levitating when he turns? [SOLVED]

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)

1 answer

I've managed to solve the issue on my own, for anyone curious, I replaced the orientation tween with a CFrame.new, making it point at a coordinate in front of it, here's the code:

local tws = game:GetService("TweenService")
local hrppos = Vector3.new(-98.342, 4.648, -41.35)
local targetPointPosition = Vector3.new(-93.152, 4.648, -43.765)
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 = {
  CFrame = CFrame.new(hrppos, targetPointPosition)
        }
        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),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)

This discussion is preserved as it was. New answers, comments, and votes are closed.