Animation on tool won't work

What do you want to achieve? I want to make my animation move on my tool.

What is the issue? My Script won’t work. Here it is:

local player = game:GetService("Players").LocalPlayer 
local character = player.Character
local Animation = script.Parent:FindFirstChild("Attack")
local AttackAnimation = character.Humanoid:LoadAnimation(Animation)

local CanAttack = true
local debounce = 0.5

script.Parent.Activated:Connect(function()
	if CanAttack then
		CanAttack = false
		AttackAnimation:Play()
		wait(debounce)
		CanAttack = true
	end
end)

and here’s a screenshot of how the parents look (i haven’t gotten to making it hit yet so that might be the case):

Bez tytułu

Help?

1 Like

Can you provide the error you’re getting? If there is no error, check if you uploaded the animation to your profile / group. If not, please do this.

1 Like

Make sure that the animation prioty is setted to Action. If that did not work, try changing the script to:
local character = player.Character or player.CharacterAdded:Wait()

If that one did not also work, try moving the AttackAnimation variable inside the function.

2 Likes

Nothing comes up in the output. And i made the animation to get the ID.

Make sure that the animation prioty is setted to Action .

This is most likely the reason if there is nothing in your output, because from what I can tell, the code you provided works fine. If the animation is NOT set to action, then it plays, and then is overrided by another animation and thus, makes it not work in your case.

1 Like

I’ll list a couple solutions which may or may not work, I can’t find the primary issue but these might help:

Instead of using player.Character to define Character, use:

local Character = player.Character or player.CharacterAdded:wait() 

You might want to use this because the character might not have loaded in and you’re attempting to essentially then find what doesn’t exist.

And when you are attempting to index or define the Humanoid, I recommend using:

local AttackAnimation = character:WaitForChild("Humanoid"):LoadAnimation(Animation) -- Again for the same reasons as above.

That’s pretty much what I could think of at the moment, if you have any other issues, you know where to find me! :smiley:

1 Like

Also if this worked, mark as solved :stuck_out_tongue:

thanks for the help! I think i found the issue but i will save this comment for later use as i’m pretty bad at coding :sweat_smile:

All good, we learn from our mistakes, correct? That’s what happens in coding. Don’t you love the small issues which ruin big projects :sweat_smile: welp, at least you found the solution, congrats.

1 Like

Yeah, i realized i had it set to Idle, but even after changing it to Action it won’t work.

Make sure you own the animation.

1 Like

welp, i tried out the other solution and it didn’t work, i tried this one and it didn’t work too, its probably something about the animation or i’m writing the code wrong… :slightly_frowning_face:

It’s either a problem on roblox’ end or you’re doing something wrong with the animation object, I don’t think you might be putting the animation id in correctly, or there’s just a general issue or glitch on your side.

1 Like

is this the correct way? Because this is the way i’ve been doing this. If it’s wrong, can you tell me how can i export it so it will work?

That seems to be right, maybe it is the way you are coding it, when I get trouble like this, I just remake the script from scratch, it helps a bunch!

1 Like

Aight, I will try from the scratch, thanks a bunch!

I also recommend you put the newly edited items in StarterPack just incase you haven’t :smiley:

I was just testing it out on the rig so i kinda forgot lol.

BTW, this is the script right now, i decided to do some changes like getting rid of debounce and changing it based on what people said, i feel like i wrote something wrong :wut:

local player = game:GetService("Players").LocalPlayer 
local Character = player.character or player.CharacterAdded:wait() 
local Animation = script.Parent:FindFirstChild("Attack")
local AttackAnimation = Character:WaitForChild("Humanoid"):LoadAnimation(Animation) 

local CanAttack = true

script.Parent.Activated:Connect(function()
	if CanAttack then
		CanAttack = false
		AttackAnimation:Play()
		wait(1)
		CanAttack = true
	end
end)

So I just tested your script out and it works perfectly fine for me, odd. I recommend turning off the tools RequireHandle property just incase nothing has worked. Otherwise I wouldn’t know what the problem was, it all works fine for me. https://gyazo.com/8b348412ad491781aab7f52099276b31

1 Like

ALSO rename your animation object to Attack if you changed it.