My action animation script doesn't seem to work

I got an action type animation script from YouTube, but it doesn’t seem to work. I’ve tried to find ways to fix this, like on YouTube and the Dev Forum, and also tried to fix it myself (although I have no experience) but they are not related to my problem or have not fixed it.

Here is my script:

Here is the error I got:

Error from Script

You can tell me if I wasn’t specific enough. Thanks!

1 Like

Everything about this is disgusting.
First off doing

script.Parent.Equipped:Connect(function(animation)

won’t work. Putting “animation” after the equipped function makes the “animation” bit of it call to the player’s mouse.

Ok now that’s addressed to fix it what you will need to do is put an animation in the tool, put the animation id in the animation, then make a variable in the script like so:

local animation = script.Parent.Animation 

and then do (above the equipped function, under the animation variable)

local animtrack = script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(animation) 

and then once in the equipped function do:

animtrack:Play()

and then once in the unequipped function do:

animtrack:Stop()

In the end it should look like this:

local animation = script.Parent.Animation 
local animtrack = script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(animation) 

script.Parent.Equipped:Connect(function()
    animtrack:Play()
end)
script.Parent.Unequipped:Connect(function()
    animtrack:Stop()
end)

Extra tip; you can’t do :Play() or :Stop() in a regular animation, you have to make an animation track like I did.

So I tried it out, and got this when clicking with the tool equipped:

Error from Script2

Also when I immediately click the “Play” button or checked the script, this shows:

Error 3

Hopefully, you can fix this. Thanks again!

Edit: My bad, I forgot to test this in all three types of scripts.

i fixed it here:

local animation = script.Parent.Idle
local animtrack = script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(animation) 

script.Parent.Equipped:Connect(function()
    animtrack:Play()
end)
script.Parent.Unequipped:Connect(function()
    animtrack:Stop()
end)

REMEMBER TO PUT IT IN A LOCAL SCRIPT!!!

It worked, but I replaced “Idle” with “Animation.” However, this makes it so that when I equip it, it plays the animation.

Thanks once again,

broke_alex

Edit: Sorry if I didn’t specify enough. I meant the animation to play when you click with the first mouse button.

local UIS = game:GetService('UserInputService')
local equipped = false

local animation = script.Parent.Idle
local animtrack = script.Parent.Parent:FindFirstChild("Humanoid"):LoadAnimation(animation) 


UIS.InputBegan:Connect(function(input)
   local inputType = input.UserInputType
   if inputType == Enum.UserInputType.MouseButton1 and equipped == true then
        
        animtrack:Play()
    end
end)    

script.Parent.Equipped:Connect(function()

    equipped = true
end)
script.Parent.Unequipped:Connect(function()

    equipped = false
end)
1 Like

Thank you so much. Also,

I had to replace “Idle” with “Animation.”

Edit: Two things that I found. So sorry that I wasn’t specifying.

  1. No matter what, when I click, it replays. I want it to be unable to replay when it is playing.

  2. The animation plays even when I click then unequip the tool. Mind if you can help?
    Meanwhile, I’ll try to solve it myself. Thanks!

animtrack:Stop() lmao, you should really read the docs and watch some tutorials, anyways.

It would be nice if you clicked the “Solution” on my comment. Thank you! :slightly_smiling_face:

I did do that, but when I deleted the last two sections of code (because I tried to solve it myself,) it all of a sudden stopped working.

I did before, but I ran into those two things.

Edit:

I found an article with a solution related to one of my problems. However, I’m scared that I will be told that I’m using someone else’s script and people will say that I’m copying. So I’m wondering: am I allowed to use other articles’ scripts?

Thanks,

broke_alex