#My cat NPC is very jittery, it sometimes randomly 'dash' forward and it stops animation when it does

1 messages · Page 1 of 1 (latest)

frigid light
#

This is the code I use for the cat movement, I use module:

local PathFinding = require(script:WaitForChild("PathFinding"))

local NPC = script.Parent
local owner = NPC.Parent

local targetPlayerRootPart = owner:FindFirstChild("HumanoidRootPart")

while true do
    task.wait(0.1)
    local ownerPos = targetPlayerRootPart.Position
    if targetPlayerRootPart then
        local distance = (NPC.HumanoidRootPart.Position - targetPlayerRootPart.Position).Magnitude
        if distance > 10 then
            PathFinding.WalkTo(NPC, ownerPos+Vector3.new(4,0,4))
        end
    end
end

The animation script:

local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local walk = animator:LoadAnimation(script:WaitForChild("Walk"))
local sit = animator:LoadAnimation(script:WaitForChild("Sit"))
local loaf = animator:LoadAnimation(script:WaitForChild("Sit to Loaf"))
local sitting = animator:LoadAnimation(script:WaitForChild("Sitting"))
local loafing = animator:LoadAnimation(script:WaitForChild("Loafing"))

humanoid.Running:Connect(function(speed)
    if speed > 0 then
        if not walk.IsPlaying then
            sitting:Stop()
            loafing:Stop()
            walk:Play()
        end
    else
        if walk.IsPlaying then
            walk:Stop()
            sit:Play()
        end
    end
end)

sit.Ended:Connect(function()
    sitting:Play()
    task.wait(4)
    sitting:Stop()
    loaf:Play()
end)

loaf.Ended:Connect(function()
    loafing:Play()
end)

I cannot find out why the cat randomly dashes forward like that. if you want, I can send the module code file since discord wont alow me to send it hee since there is a text cap. the code is too long

rotund echo
#

could also be network ownership but i doubt it

tacit timberBOT
#

studio** You are now Level 6! **studio

rotund echo
#

that doesn't have WalkTo in it.

frigid light
#

oh wait wrong copy sorry

#

and yes, it uses humanoidrootpart

rotund echo
# frigid light this one

with the way that works and the fact you are calling it every 0.1 seconds i'm not surprised its movement is janky

#

hm, no, i'm thinking of runservice.heartbeat and thats just a while loop

#

ah yes you do have double move in there

frigid light
#

double move?

rotund echo
#
        moveToConnection = humanoid.MoveToFinished:Connect(function(reached)
            if reached and waypointIndex < #waypoints then
                waypointIndex += 1
                humanoid:MoveTo(waypoints[waypointIndex].Position)
            else
                cleanupMoveTo()
            end
        end)

...
        while moveToConnection do
            task.wait(stuckCheckTime)
            if not moveToConnection then break end

            if (humanoidRootPart.Position - lastLocation).Magnitude < 1 then
                cleanupMoveTo()
                teleportCharacter(character, position)
                break 
            end
            lastLocation = humanoidRootPart.Position
        end```
that's gonna be very jank
#

and then add on the network ownership problem

#

ye i think just set network owner to nil and it might work a little better

frigid light
#

but the network owner is nill

rotund echo
#

otherwise a player might get ownership of it

#

if a player does get ownership, it's going to move very janky

#

since the server is trying to move it while the player owns it

frigid light
#

it is, on line 44

    humanoidRootPart:SetNetworkOwner(nil)
rotund echo
frigid light
#

in pcall function

rotund echo
#

that's a pretty dum place for it but eh as long as its getting called

muted mantle
#

maybe its just a bad kitty

#

tell it to be a good kitty

#

might work 🤷‍♂️

frigid light
frigid light
rotund echo
#

this task.wait is messing up the sit animation lua sit.Ended:Connect(function() sitting:Play() task.wait(4) sitting:Stop() loaf:Play() end)

#

since it will stop the sit animation and play loaf 4 seconds later regardless of what the cat is doing at that moment

frigid light
#

yeah, but the sit animation will only play when the cat isnt doing anything

muted mantle
#

the script works on a normal rig (not animations obv) 🤷‍♂️

#

a normal rig follows me around just fine

rotund echo
muted mantle
#

maybe its the cat's model?

frigid light
rotund echo
#

why not just .looped=true?

#

idk that just looks really weird to me, like you cannot interrupt the sit properly

frigid light
#

sit and sitting are two different animations, sit is from standing to sit, sitting is looping the sitting position

muted mantle
#

cuz I obv dont have the animations

#

the normal script + module script works perfectly fine on a normal rig

#

blocky rig

frigid light
#

then I guess its the animations

#

ill look into it, thank you guys

muted mantle
#

but the animations wont teleport the cat around

#

the cat gets teleported to somewhere far in that vid

rotund echo
muted mantle
#

try disabling the animation script

muted mantle
frigid light
rotund echo
muted mantle
#

i think its just the rig

#

my new best friends follows me around fine

frigid light
#

yep, definitely with the rig or animations, its moving peroperly after i disabled the animation scripts

muted mantle
#

hey look at that!

#

im Sherlock

rotund echo
frigid light
rotund echo
#

just be careful with how you use that

muted mantle
muted mantle
#

yea

muted mantle
#

but network ownership is nil

muted mantle
#

I read it wrong

frigid light
#

i dont think the animation code it the problem, maybe the way i animated it

rotund echo
# frigid light i used a server script

you do not have a server script there. you have a script with runcontext set to client, therefore it becomes a kind-of localscript. i never suggest beginners mess with that because it can lead to unexpected and very hard to diagnose bugs

#

just set its runcontext back to legacy.

frigid light
#

okay, wait a se

#

but wouldnt that make it laggy? or would the lag be negligable?

muted mantle
#

prob wont lag that much

#

animations played by the client are replicated to server too so uh

#

thats not very laggy either

rotund echo
#

most things that beginners think will be laggy really won't be.

muted mantle
#

stuff like VFX gets laggy but animations dont really

#

I mean if they did lag the server then I doubt roblox would have ever made the animations being replicated from client to server 🤷‍♂️

frigid light
#

okay, I changed it to legacy and now its not that jittery anymore but now the animations arent playing properly

#

I think it might be 'if speed > 0 then' but i dont know how else to check if its moving or not

rotund echo
#

idk why humanoid.running is glitchy

frigid light
#

okay wait, lemme see how to do that

rotund echo
frigid light
#

changed it, but now it's not playing any animation at all

rotund echo
#

pretty sure humanoid:moveto will change movedirection thonkoof

#

it might just be for players

frigid light
#

I also tried 'humanoid.MoveDirection.Magnitude > 0' since I saw it in roblox examples but it didnt work

rotund echo
muted mantle
#

idk maybe try checking the velocity

rotund echo
muted mantle
#

doesnt the velocity change when u start walking

rotund echo
#

i dont think that fires propertychanged signals

#

never tested it tho (or if i did i dont remember), but i very much doubt

frigid light
muted mantle
rotund echo
muted mantle
#

not yet

#

I quit for 6 months

#

I reecntly started

#

again

frigid light
#

hmm?

rotund echo
#

i'm too lazy to do it half the time these days, but for my own projects everything has to be tested and it is exhausting. shows s2 tier work though, s1's have a hard time setting up tests

muted mantle
#

idk im trying to use Rojo rn

#

kind of inconvenient

rotund echo
# muted mantle kind of inconvenient

i don't bother, studio is good enough on its own and i figure packages are the way to go if you want to spread the work without giving away the entire project

muted mantle
#

its cool tho

#

feels cool

rotund echo
muted mantle
#

im only doing it cuz it feels cool ;P

#
  • it seems like a useful thing to learn
frigid light
#
humanoid.Running:Connect(function(speed)
    if speed > 0 then
        if not walk.IsPlaying then
            sitting:Stop()
            loafing:Stop()
            walk:Play()
            print("walking")
        end
    else
        if walk.IsPlaying then
            walk:Stop()
            sit:Play()
            print("not walking")
        end
    end
end)

it prints both... so the animation is stopping and starting and stopping and starting...

rotund echo
tacit timberBOT
#

studio** You are now Level 43! **studio

frigid light
#

getpropertychangedsignal is not a valid member of Humanoid "Workspace.HannazRolynn.Kitty.Humanoid"

rotund echo
#

if ur gonna get into scripting, google every error, without exception. it should be automatic response.

frigid light
#

my bad

muted mantle
muted mantle
#

are you trying to do Humanoid.GetPropertyChangedSignal?

#

its Humanoid : GetPropertyChangedSignal

muted mantle
muted mantle
# frigid light my bad
        Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
            if Humanoid.MoveDirection == Vector3.zero then
                --Stopped
            else
               --Walking
            end
        end)
frigid light
#

its not firing, nothing was printed

muted mantle
#

are you doing it on a local script or sm

#
local Players = game:GetService("Players")
Players.PlayerAdded:Connect(function(Player)
    Player.CharacterAdded:Connect(function(Character)
        local Humanoid = Character:FindFirstChildOfClass("Humanoid")
        Humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
            if Humanoid.MoveDirection == Vector3.zero then
                print(Player.Name.." is standing still")
            else
                print(Player.Name.." is walking")
            end
        end)
    end)
end)

I did this and uh

frigid light
#

its on a server script

muted mantle
#

works fine

frigid light
#

I did

local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local walk = animator:LoadAnimation(script:WaitForChild("Walk"))
local sit = animator:LoadAnimation(script:WaitForChild("Sit"))
local loaf = animator:LoadAnimation(script:WaitForChild("Sit to Loaf"))
local sitting = animator:LoadAnimation(script:WaitForChild("Sitting"))
local loafing = animator:LoadAnimation(script:WaitForChild("Loafing"))

humanoid:GetPropertyChangedSignal("MoveDirection"):Connect(function()
    if humanoid.MoveDirection == Vector3.zero then
        walk:Stop()
        sit:Play()
        print("not walking")
    else
        sitting:Stop()
        loafing:Stop()
        walk:Play()
        print("walking")
    end
end)

sit.Ended:Connect(function()
    sitting:Play()
    task.wait(4)
    sitting:Stop()
    loaf:Play()
end)

loaf.Ended:Connect(function()
    loafing:Play()
end)

and nothing was printed

tacit timberBOT
#

studio** You are now Level 7! **studio

muted mantle
#

it wokrs on client too

#

idk

frigid light
#

does it only work on players?

muted mantle
#

wait

#

ill try

#

yes.

#

only works on players

frigid light
#

oh

muted mantle
#

;-;

rotund echo
muted mantle
#

idk humanoid.Running is working for me

#

just use the pathfindingservice

#

to add animations

frigid light
#
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")

local walk = animator:LoadAnimation(script:WaitForChild("Walk"))
local sit = animator:LoadAnimation(script:WaitForChild("Sit"))
local loaf = animator:LoadAnimation(script:WaitForChild("Sit to Loaf"))
local sitting = animator:LoadAnimation(script:WaitForChild("Sitting"))
local loafing = animator:LoadAnimation(script:WaitForChild("Loafing"))

humanoid.Running:Connect(function(speed)
    if speed > 0 then
        if not walk.IsPlaying then
            sitting:Stop()
            loafing:Stop()
            walk:Play()
            print("walking")
        end
    else
        if walk.IsPlaying then
            walk:Stop()
            sit:Play()
            print("not walking")
        end
    end
end)

sit.Ended:Connect(function()
    sitting:Play()
    task.wait(4)
    sitting:Stop()
    loaf:Play()
end)

loaf.Ended:Connect(function()
    loafing:Play()
end)