Why isn't my animation working and how do i stop an event from running multiple times?

I am trying to play a kicking animation when the player hits a hitbox but the animation will not play and the function seems to be repeating multiple times. I haven’t been able to find the solution, here is my code:

local char = script.Parent
local hum = char:FindFirstChild("Humanoid")
local hitbox = game.Workspace.football.hitbox
local rs = game:GetService("ReplicatedStorage")
local re1 = rs:FindFirstChild("FireKickAnim")

local kickAnim = hitbox.KickAnim
local kickAnimTrack = hum:LoadAnimation(kickAnim)
hitbox.Touched:Connect(function(hit)
	re1.OnClientEvent:Connect(function(shotpower)
		if shotpower > 1 then
			kickAnimTrack:Play()
			print("done")
		end
	end)
end)

This code is placed inside a character and is a local script. It prints “done” approximately 100 times every test. If you can, please help. Thank you :pray:

1 Like

Did you forget to set the AnimationId?

Try adding a debounce like in this example, it should limit it until the event finishes:

local debounce = false

TestFunctionExample.OnTestEvent:Connect(function()
   if debounce == true then return end
   debounce = true
   -- code
   debounce = false
end)

I gotta go to sleep but yeah just gonna leave this here