Tool Holding Animation


image

So I have a local script under a tool and when it is equipped it plays the holding animation. It works fine unless I reset and then when I equip the tool again it doesn’t play the animation and I get this error. Does anyone know why?

1 Like

ig doing:

if humanoid and (Tool.Parent.Parent == workspace) then

will fix it

that is really weird. I wonder why you would have to do that

it is what it is, try it and see if the error occurs again.

nothing changed i still get the error

is your animation a descendant of workspace?

Just do this:

Tool:IsDescendantOf(workspace)

yeah it is (extra character and stuff)

never heard of that function, but thanks for giving me new knowledge

alright so i think the error occured because your roblox character hasn’t loaded completely yet. after resetting, try waiting a few seconds and try equipping it again. if it worked try figuring out how to make the player unable to equip the tool before their character has fully loaded.

1 Like

no even if i wait it still doesn’t play

still error?


yeah i still get the same error

local ReplicatedStorage = game:GetService("ReplicatedStorage")

local player = game.Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")


--------

local RemotesFolder = ReplicatedStorage:WaitForChild("CombatRemotes")
local DamageRemote = RemotesFolder:WaitForChild("Damage")

--------

local Tool = script.Parent
local Handle = Tool:WaitForChild("Handle")
local HitBox = Tool:WaitForChild("HitBox")

--

local AttackAnimsFolder = Tool:WaitForChild("AttackAnimations")
local AnimsFolder = Tool:WaitForChild("OtherAnimations")



--

local AttackAnims = {
	
	AttackAnimsFolder:WaitForChild("Attack1"),
	AttackAnimsFolder:WaitForChild("Attack2"),
	AttackAnimsFolder:WaitForChild("Attack3"),
	
}

local comboNumber = 1
local lastHitTime = 0
local canHit = true
local canDamage = false

local comboResetTime = 1

local timeInBetweenAttacks = 0.1

Tool.Activated:Connect(function()
	
	if canHit == true then

		if tick() - lastHitTime > comboResetTime then

			comboNumber = 1

		end


		lastHitTime = tick()

		canHit = false
		canDamage = true

		local animation = animator:LoadAnimation(AttackAnims[comboNumber])
		animation:Play()
		print(comboNumber)

		if comboNumber == #AttackAnims then

			timeInBetweenAttacks = 0.4

		else

			timeInBetweenAttacks = 0.1

		end

		task.wait(animation.Length + timeInBetweenAttacks)
		canHit = true
		canDamage = false


		if comboNumber == #AttackAnims then

			comboNumber = 1

		else

			comboNumber += 1

		end
	end	
end)

-------

HitBox.Touched:Connect(function(hit)
	
	if canDamage then
		
		if hit.Parent.Name ~= character.Name then

			if hit.Parent:FindFirstChild("Humanoid") then

				local hitHumanoid = hit.Parent:FindFirstChild("Humanoid")
				
				if hitHumanoid.Health > 0 then
					
					canDamage = false
					DamageRemote:FireServer(hitHumanoid, Tool)
					
				end

			end

		end
		
	end
	
end)


local holdingAnim

Tool.Equipped:Connect(function()
	
	if humanoid and Tool:IsDescendantOf(workspace) then
		
		holdingAnim = animator:LoadAnimation(AnimsFolder:WaitForChild("Hold"))
		holdingAnim:Play()
		
	end

end)

Tool.Unequipped:Connect(function()
	
	if holdingAnim then
		
		holdingAnim:Stop()
		
	end
	
end)

here is the full script if that helps

ok so try

repeat
	task.wait()
until character:IsDescendantOf(workspace)

put it in your script below local character
sorry i did a few english errors.

i dont get the error anymore but now it does nothing like its still waiting for the character to be a child or something

below my code that i just sent write print("running tool"), just to know whenether it’s running yet or not.

should i just send a remote event to the server and have the server play the animation? i would prefer not to do that but if that is the only thing that will work

i suppose that won’t work?


alright ill try that. this minimum chracter thing is annoying