Hit Animation Delay

Basically, I’ve made a weapon combat system and everything works really smooth, except when it comes to playing the hit animations


(Ignore that the hitting animation also plays on my character, It’s a simple fix)

I have no idea what’s causing this delay, I’ve been trying to figure it out for days now but still didn’t reach anything.

Here’s the scripts:
Server side:

local function AnimNumber(Blocker)
	if Blocker then
		animnum = animnum + 1
		if animnum == 3 then
			animnum = 1
		end
		game.ReplicatedStorage.Remotes.HitClient:FireClient(Blocker, animnum)
	end
end

local function stun(plr)
	coroutine.wrap(function()
		plr.Stun.Value = true
		plr.Character.Humanoid.WalkSpeed = 0
		plr.Character.Humanoid.JumpPower = 0
		wait(0.7) 
		plr.Stun.Value = false
		plr.Character.Humanoid.WalkSpeed = 16
		plr.Character.Humanoid.JumpPower = 50
	end)()
end

if plr:FindFirstChild("Stun").Value == false and plr.Block.Value == false  then
			if not humanoid.Parent:FindFirstChild("CustomNPC") then
				if	Blocker.Block.Value == false then
					AnimNumber(plr)
					humanoid:TakeDamage(damage)
					stun(Blocker)
					AnimNumber(Blocker)
				elseif Blocker.Block.Value == true then
					if BlockDirection(Blocker,plr) == true then
					AnimNumber(plr)
					humanoid:TakeDamage(damage)
					stun(Blocker)
					AnimNumber(Blocker)
					game.ReplicatedStorage.Remotes.BlockBreak:FireClient(Blocker)
					Blocker.Block.Value = false
					end	
				end

Thank you for reading :slight_smile:

1 Like

The problem is that you’re doing the animation on the server, instead do it on a client, fire a remote to the server and then do the animation again on the server, this will:

  1. Remove delay, anything from the server takes a bit of time to replicate to the client bcz of latency.
  2. Play the animations for others too.

I am not though, I’m firing a remote to the client

local function AnimNumber(Blocker)
	if Blocker then
		animnum = animnum + 1
		if animnum == 3 then
			animnum = 1
		end
		game.ReplicatedStorage.Remotes.HitClient:FireClient(Blocker, animnum)
	end
end

Try printing this throughout the script to see if anything is getting delayed for some reason.

local start = os.clock()
--some function
print(os.clock() - start)

Also make sure that the animation isn’t actually delayed itself, like the keyframes. Animation priority might also be the problem, check if it’s on action.

I see that you are firing an event to the hit client → Which is good.

But the issue is that firing an event takes a little bit of time too, which is not avoidable.

I’d suggest you a different approach:

Rather than making the server let the client know it’s been hit;
Make the client detect whether it’s been hit.

That way, the client indepentdantly detects a hit, and runs the animation, rather than waiting for the server to let it know.


A few ways to do this:
Humanoid.HealthChanged --Detect when a humanoid was damaged.
BodyPart.Touched --Detect if the torso was hit by a tool.
Intro to Raycasting --You can also utilize raycasting to check if there’s a weapon in front of the character.