How do I fix this error with my tool holding animation script?

Any help would be greatly appreciated, error & setup shown in the photo

local tool = script.Parent.Parent

tool.Equipped:Connect(function()
	local player = tool.Parent:WaitForChild("Animate")
	player:WaitForChild("toolnone"):WaitForChild("ToolNoneAnim")
	player.toolnone.ToolNoneAnim = script.Holding -- Name of the animation, inside of the script
end)

You’re trying to define 2 Instances with each other, which doesn’t work that way

There’s a couple of ways you could work with this here:

  • Playing the Holding Animation via the LoadAnimation function with the Animator
  • Your idea (You’ll have to change the AnimationId inside the Animation Object you’re attempting to change, not 2 Instances)
  • Completely overlap the Default Animations with your own by replacing the default Animate Script and putting it in StarterCharacterScripts (Which requires a couple steps)

Example 1:

local Tool = script.Parent
local Char, Animate

Tool.Equipped:Connect(function()
    Char = Tool.Parent
    Animate = Char:WaitForChild("Animate")

    Animate.toolnone.ToolNoneAnim.AnimationId = script.Holding.AnimationId
end)

Example 2: (My personal thought)

local Tool = script.Parent
local Char, Hum, Animator
local CurrentAnim = nil

Tool.Equipped:Connect(function()
    Char = Tool.Parent
    Hum = Char:WaitForChild("Humanoid")
    Animator = Hum:WaitForChild("Animator")

    CurrentAnim = Animator:LoadAnimation(script.Holding) -- Make sure to set this as Action or Higher
    CurrentAnim:Play()
end)

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

Seems like this fixed to the first error but now I’m getting the error “LoadAnimation requires an Animation object” with your second piece of code. How do I go about fixing this?

Where are you calling LoadAnimation?

Line 10, I think it’s an issue with how I set up the animation

(@JackscarIitt’s Example #2)

The script in the screenshot has 7 lines.

I noticed that too, but that leads to the error “(line 10) LoadAnimation requires an Animation object”

Well if that’s the case, are you using an Animation Object? Not a Keyframe Object or something along those lines

Only other thing that I could see is that you have a duplicate object named the same thing, but I don’t see that anywhere within the Script’s Boundaries

I made a holding animation that copied & pasted it out of AnimSaves.
Screen Shot 2022-03-06 at 4.40.15 PM

That’s a Keyframe then

local Tool = script.Parent
local Char, Hum, Animator, CurrentAnim

local HoldingAnim = Instance.new("Animation")
HoldingAnim.Name = "Holding"
HoldingAnim.AnimationId = "rbxassetid://AnimationIDHere"

Tool.Equipped:Connect(function()
    Char = Tool.Parent
    HoldingAnim.Parent = Char

    Hum = Char:WaitForChild("Humanoid")
    Animator = Hum:WaitForChild("Animator")

    CurrentAnim = Animator:LoadAnimation(HoldingAnim) -- Make sure to set this as Action or Higher
    CurrentAnim:Play()
end)

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

What you should do instead is try & find the AnimationId of that Holding Animation you created, and input it onto the AnimationIDHere reference

This should work, cause Keyframes are not actual Animation Objects for the LoadAnimation function to work, and that’s why the error keeps happening

1 Like

Is there a way to do it without animation ID? It limits you from using the model outside of personal/group games because you have to reupload the animation every single time it changes hands.

I believe there is:

https://developer.roblox.com/en-us/api-reference/function/KeyframeSequenceProvider/RegisterKeyframeSequence

1 Like

That kind of kills my hopes of making it into a publishable model but thanks for your help and fixing my script