Script I made won't display custom tool holding animation for a flashlight?

So I’m still working on my game, and I’m trying to get the tool animations I’ve already made to play for their respective tools. I’ve got the ones for stabbing with the spear and bonking with the hammer to play, but for animations for holding other tools… I can’t get it to work.

Here is my holding animation I want to play for the flashlight:

Here is my code:



local tool = script.Parent

local animation = script.Flashlight

local humanoid = tool.Parent.Parent:FindFirstChild(“Humanoid”)

local track = humanoid:LoadAnimation(animation)

track.Looped = true

tool.Equipped:Connect(function()

	track:Play()

end)

tool.Unequipped:Connect(function()

	track:Stop()

end)

What am I missing here?

3 Likes

humanoid:LoadAnimation(animation) is deprecated use

humanoid.Animator:LoadAnimation(animation)

1 Like

…I feel kinda dumb now. Then again I’m not exactly a scripter at heart, and I didn’t know that was deprecated. However, the problem still remains.

when you were animating did you set the animation priority to action?

I set it to action, so the animation of the arm should display on top of the animation for moving.

Try to load the animation when the tool is equipped. I had a similar problem and it solved it.

But isn’t that what my script is supposed to be doing anyway?
I don’t fully understand to be clear.

I am not an expert, but from my understanding, the animation won’t load if it is not inside a function, at least that was my case. Try it and see if it works.

I spent a few minutes thinking about how to order it, and came up with nothing. As I’ve said, scripting is not my strong point… a little more help please?

Basically


local animation = script.Flashlight

local humanoid = tool.Parent.Parent:FindFirstChild(“Humanoid”)

offTrack = nil


tool.Equipped:Connect(function()
        local track = humanoid:LoadAnimation(animation)
        offTrack = track
        track.Looped = true
	    track:Play()

end)

tool.Unequipped:Connect(function()

	offTrack:Stop()

end)```

So the finished script would look like this?


local tool = script.Parent

local animation = script.Flashlight

local humanoid = tool.Parent.Parent:FindFirstChild(“Humanoid”)

offTrack = nil


tool.Equipped:Connect(function()
	local track = humanoid:LoadAnimation(animation)
	offTrack = track
	track.Looped = true
	track:Play()

end)

tool.Unequipped:Connect(function()

	offTrack:Stop()

end)```

Yes, try to put local before offTrack btw as I forgot, try to copy and paste it and see if it helps.

It’s still not working, what’s wrong now?

Now I have no idea, I only ran into this problem once and the thing I proposed above worked, I have no idea on what I can do to help now.

Dang it. This is a lot more tricky than I thought…

Hey, here’s a general script for animations when a tool is equipped, this should help you.

local Tool = script.Parent
local Player = game.Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local EquipAnim = Tool.Equip

local Equip = Character.Humanoid.Animator:LoadAnimation(EquipAnim)

Tool.Equipped:Connect(function()
	
	Equip:Play()
	
end)

Tool.Unequipped:Connect(function()
	
	Equip:Stop()
	
end)

It should be noted that this is a local script.

So do I put the animation I want to play as a child of the tool or a child of the script?

In accordance with my example, it would be a child of the tool, however this shouldn’t matter where you put it, just make sure you path properly in the code.

The script isn’t working… what’s wrong now?

  1. Can you send your code?
  2. Any errors?
  3. You should double check that your animation is set to action priority
  4. Is your code in a local script or a server script?