How do i make idle animation plays if the player is idle only?

  1. What do you want to achieve?
    How do i make idle animation plays if the player is idle when equipping sword only?
  2. What is the issue?
    Idle animation still plays when player moves with the sword equipped


(Sorry i forgot to put the vid)

  1. What solutions have you tried so far?
    i tried searching yt and other social media but seems like i couldn’t find any

btw heres the code

local player = game.Players.LocalPlayer

repeat wait(1) until player.Character

local character = player.Character
local humanoid = character:WaitForChild("Humanoid")

local animation = script.Animation
local animtrack = humanoid:LoadAnimation(animation)

script.Parent.Equipped:connect(function()
	animtrack:Play() -- Plays Idle Animation
end)

script.Parent.Unequipped:connect(function()
	animtrack:Stop() -- Stops Idle Animation
end)

How i would achieve this is changing the code for the character animation script. i would run childadded and childremoved on the character and if child:IsA “Tool” then apply that tools specific animation. you can achieve this by creating a startercharacter and putting it in starterplayer and then editing the animtion code. make sure to load player appearance on char too and it will be the same

1 Like

Weird. It should work. Are you sure that your animation’s priority is set to ‘Action’?

1 Like

That isn’t the issue. If there was any issue with the animation then it would be .Looped being off. If hes playing an idle animation then im assuming nothing else is playing when it runs on equipped. Meaning its either not .Looped or it isn’t playing cause of the Animations script. Which is why i proposed my method which would allow him to set up multiple tools in the future without the need of having a script inside every single tool and making it very easy to edit

1 Like

Thanks for your reply. Actually the problem is when player moves with sword equipped, the idle animation still play…

1 Like

Hello Sorry for misunderstanding, actually the issue is:

1 Like

Yes thats why i said to edit the animation script code. Since you would only be changing the animation id. All you would be doing is changing the idle to the new idle. And when they unequip revert to the default. You wouldnt need to code anything else. But if you really don’t want to do that then you’re going to need to add

Humanoid.Running:connect(myFunc)

What this will do is call myFunc everytime your characters speed changes.
The link below shows how you would use this to determine if their speed is currently 0 or not. All you need to do is make your Idle animation not run if speed > 0

https://developer.roblox.com/en-us/api-reference/event/Humanoid/Running

2 Likes

I used the Humanoid.Running method and It works! Thank you very much sir. I appreciate your helps :grinning_face_with_smiling_eyes: :grinning_face_with_smiling_eyes:

1 Like

Use the Player.Idled event. Which is fired whenever the game detects that the player is idle.

https://developer.roblox.com/en-us/api-reference/event/Player/Idled

1 Like

Bad idea, i’ve tried it multiple times and it breaks the Walk animation (which is using Humanoid.Running too).

Maybe it is just outdated but i wanted to point this out for new people looking into this topic.

2 Likes

This does work. Are you sure your animation is set to a priority higher than Core?
I have several games actively using this sort of interpretation and I’ve yet to come across the walk animation “breaking”

1 Like

Could you show how you used the function in your script?

1 Like