Animation REFUSES to play when tool is activated

I have an animation, or well, a code that SHOULD run when the tool is activated, but the first print statement doesn’t even run, and I don’t know why.

local plr = game:GetService("Players").LocalPlayer
local Char = plr.Character or plr.CharacterAdded:Wait()
local Mouse = plr:GetMouse()
local Tool = script.Parent
local anim = Tool:WaitForChild("shovelAttack")
local attack1 = Tool:WaitForChild("HurtPart"):WaitForChild("AttackScript1")
local attack2 = Tool:WaitForChild("HurtPart"):WaitForChild("AttackScript2")
local values = {}
local attackEvent1 = game:GetService("ReplicatedStorage"):WaitForChild("Attack1Shovel")
local attackEvent2 = game:GetService("ReplicatedStorage"):WaitForChild("Attack2Shovel")
local DattackEvent1 = game:GetService("ReplicatedStorage"):WaitForChild("attack1")
local swingSound1 = Tool:WaitForChild("HurtPart"):WaitForChild("SwingSound")
local swingSound2 = Tool:WaitForChild("HurtPart"):WaitForChild("SwingSound2")
local db = false

-- EVERYTHING HAPPENS HERE
Tool.Activated:Connect(function()
	print("activated") -- this DOESN'T run
	local animator = Char.Humanoid:FindFirstChildOfClass("Animator")
	if db == false then
		db = true

		if animator then 
			local Attack = animator:LoadAnimation(anim)
			Attack:Play()
			swingSound1:Play()
			Attack.KeyframeReached:Connect(function(Attack1Frame)
				if not values.Button1 then
					Attack:Stop()	
				else
					print("event1 fired")
					attackEvent1:FireServer(attack1)
				end
			end)
			Attack.KeyframeReached:Connect(function(Attack2Frame)
				if not values.Button1 then
					Attack:Stop()
					DattackEvent1:FireServer(attack1)
				else
					print("event2 fired")
					attackEvent2:FireServer(attack2)
					swingSound2:Play()
				end
			end)
		end
		task.wait(1.75)
		db = false
	end
end)

Mouse.Button1Down:Connect(function(input, gameProcessed) 
	if gameProcessed then return end

	values.Button1 = true
end)

Mouse.Button1Up:Connect(function(input, gameProcessed) 
	if gameProcessed then return end

	values.Button1 = false
end)
2 Likes

Most likely, one of the :WaitForChild(s) are yielding the script, not letting the event run.

Yields DO affect events.

2 Likes

Add a print before the Event, as said by @remcodesremcodes the script might be yielding, so be sure to check if the script is even running

2 Likes

wow, i can’t believe that was the problem :sob:

thanks!!!

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.