Unable to animate in a tool

Hello,

I’m trying to create a tool that has an animation for when you equip it, but the Animator object is not getting the animations. Here is the error message:


Here is the code:
image
That last line is what is causing the error. What can I do to fix this?

*Edit: yes, there are animation Instances parented under the tool.
image

3 Likes

Is the tool in the workspace or in the StarterPack?

If the tool in the StarterPack (which is now in the player’s backpack), it’s probably can’t see the local player since the local player = script.Parent.Parent.Parent is referring to the Players Service and not the actual player (in which it can’t find the animator in the humanoid).

2 Likes

Do I need to wait until the parent is a player?

2 Likes

There is a Event for the tool called Equiped; when the item is equipped, it will fire and then the player can do an idle animation.

2 Likes

Alright, I will try that out. Thanks!

2 Likes

Nothing happens when I equip the tool
image

I did idleTrack:Play() as well

2 Likes

I don’t really know, can you check the idle animation ID on the animation instance in the tool?

2 Likes

I don’t know either, there is an animation ID in the Instance.

1 Like

Yeah, is the animation ID correct?

1 Like

Yes, I created the animation, published to Roblox, copied the ID, and put it in the animation.

1 Like

Can you give me the whole script and I’ll see what I can do.

1 Like
local cd = 0.75
local damage = 10

local tool = script.Parent

local idleAnim = tool.Idle
local attackAnim = tool.Attack

local player = script.Parent.Parent.Parent

local c = player.Character
local animator = c.Humanoid:WaitForChild('Animator')



local playingIdle = false

tool.Equipped:Connect(function()
	local idleTrack = animator:LoadAnimation(idleAnim)
	print('equipped')
	playingIdle = true
	idleTrack:Play()
	
	idleTrack:GetMarkerReachedSignal('Ended'):Connect(function(param)
		if playingIdle then
			print(param)
			idleTrack:Play()
		end
	end)
end)

tool.Unequipped:Connect(function()
	print('unequipped')
	playingIdle = false
end)

	



local onCd = false

local touchable = false
local touched = false

tool.Activated:Connect(function()
	local attackTrack = animator:LoadAnimation(attackAnim)
	print('activated')
	if not onCd then
		onCd = true
		playingIdle = false
		attackTrack:Play()
		tool.Swing:Play()
		wait(0.25)
		touchable = true
		attackTrack:GetMarkerReachedSignal('Punch Ended'):Connect(function(param)
			print(param)
			wait(0.25)
			playingIdle = true
			touchable = false
		end)
		wait(cd-0.5)
		touched = false
		onCd = false
	end
end)
1 Like

There are a couple things you can do that I can think of. One of it is:

You can copy and paste the whole script into a local script (local changes to the character model, like animations, are replicated to the server). Also, you can replace the local player = script.Parent.Parent.Parent to local player = game:GetService("Players").Player

1 Like


image
WaitForChild is a default Roblox function, why is it not working??

1 Like

The script in the tool runs faster than the character fully loading; basically the player.character haven’t fully loaded yet. So, you can replace the local c = player.Character or player.CharacterAdded:Wait()

2 Likes

Nothing happens when I equip the tool

Also, are you trying to loop the animation with this?

idleTrack:GetMarkerReachedSignal('Ended'):Connect(function(param)
		if playingIdle then
			print(param)
			idleTrack:Play()
		end
	end)

[/quote]

Yes, it’s an idle animation so it should loop

For the animation add-on you are using, there should be a toggle for looping the animation.

If you do so, you can play the looping idle animation and it will loop.

image
Is it this right here or is that for displaying the loop while editing?