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:
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).
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)
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
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()