Best way to link animations to attack VFX/Hitboxes?

I want to do things like toggling a trail on/off, or trigger other graphical effects for an attack, but firing 3 different remote events to turn on the trail, activate the hitbox, then turn off the trail, is obviously really silly and unoptimal.

For example with a punch, what I’m doing right now is this:

FistPunch1:GetMarkerReachedSignal('AnimStart'):Connect(function()
	Humanoid:SetAttribute("Attacking", true)
	PunchCooldown = true
	Humanoid.WalkSpeed += 12
end)

FistPunch1:GetMarkerReachedSignal('PunchHit'):Connect(function()
	FistPunchRE:FireServer(CurrentAttack)
	
	Humanoid.WalkSpeed -= 20
	wait(0.5)
	Humanoid.WalkSpeed += 8
end)

FistPunch1:GetMarkerReachedSignal('AnimEnd'):Connect(function()
	CurrentAttack = 2
	
	wait(0.3)
	Humanoid:SetAttribute("Attacking", false)
	PunchCooldown = false
end)

What I thought the next solution would be was to replicate the animations to everyone with FireAllClients (since this would also further reduce lag by running anims client sided) and then using the animation events there, but that seems like a bit of a commitment and I’m not 100% sure how that is set up (I get the concept, but execution is always harder)

If you could explain a good or easier alternative, or link me to any resources that might be helpful, that’d be great

2 Likes

You could try handling it all on the server if it is going to be replicated to all clients anyways. Unless there is a specific benefit of using the client I think you should just use the server for handling this.

Also, off-topic, it’s generally bad practice using += or -= on the Humanoid WalkSpeed because it could cause incorrect WalkSpeed if an event is somehow fired multiple times before debounce is set. Try just using =.

Use one remote event from the client that signals the start of an attack. When the server receives the event, the server can calculate the damage and another remote can be fired to the other clients letting them know they should show the attack visuals.

I’ve just heard it’s bad practice to run it on the server and was wondering if it was better to run it on the server, or to replicate it instead

Is it fine to run animations server side performance-wise since it replicates to everyone even if it was done client-sided?

Thing is that if I replicate it, I can’t do animation events server-sided and idrk what to do about that…