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

How can i make an idle animation play for my tool when my character's standing still?

i've been trying to give my lightsaber tool an idle and run animation. i've gotten the running part down but i can't figure out how to play the animation when the player's standing still. here's my code:

Tool.Equipped:Connect(function()
    humanoid.StateChanged:Connect(function(oldState, newState)
        if newState == Enum.HumanoidStateType.Running then
            runAnim:Play()
            idleAnim:Stop()
        elseif oldState == Enum.HumanoidStateType.None then
                runAnim:Stop()
                idleAnim:Play()
    end
    end)
end)

nothing prints in the output so i don't know how to fix it, please help!

2 comments

0

swap lines 4 and 5

0

i tried that and got the same result

1 answer

✓ Accepted answer

Instead of checking the humanoid's state, try using the velocities of the HumanoidRootPart in the character.

You can place this in a local script inside the tool:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local HumanoidRootPart = Character.HumanoidRootPart

local Running = false -- checks last state

coroutine.resume(coroutine.create(function()
	while wait() do
		 if HumanoidRootPart.Velocity.magnitude >= 1 and not Running then
			Running = true
			idleAnim:Stop()
			runAnim:Play()
		elseif HumanoidRootPart.Velocity.magnitude < 1 and Running then
			Running = false
			runAnim:Stop()
			idleAnim:Play()
		end
	end
end)

Basically the script checks to see whether the player was last running, and if the player was last running and the velocity of the torso is less than 1, then the character idles. However, if the player was not running and the velocity of the torso is greater than or equal to 1, the character runs.

I hope this helps!

Edit: this script is just an example of how to use the velocity of the HumanoidRootPart and not meant to be used in replacement of the script, but if you use this make sure you define what runAnim and idleAnim are

2 comments

0

thank you! i'll try this out

0

it works!!! thank you so much i've been trying to figure this out for the longest time!!!

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