Should NPC animations with hitboxes and animation-events be server sided or localized

So I am making an NPC that attacks using energy blasts and animation and all that. My question is that I keep reading that animations should play from a local script that fires for all clients to see the same exact NPC doing the same movement, but if the animation is a skill like magic beams, shouldn’t the animation be server-sided so that the magic skill or whatever synchronizes hitting the player? i tend to think localized animations have some real time delay or am i wrong? thanks for answering

The server needs to replicate the keyframes to the client anyways when playing the animation on the server side, so it doesn’t cost anything to have the client play the animation instead.

It’s always a better idea to play animations on the client, in the rare exception you’re using AnimationEvents to determine when attacks, but AnimationEvents are only useful for games that have timeslow mechanics.

so should I not use animationEvents? I’m trying to perfectly time some vfx with the animation thats why im using animationEvents, but let me know if theres a better way. also what do you mean timeslow mechanics?

No. You can achieve a similar effect with task.wait() as long as you memorize when the event needs to happen. If your visual effects are being delayed, that might be because you’re doing the visuals on the server instead of the client.

In very certain games, a developer might want to implement a timeslow mechanic, where time is slowed for a period of time. Think of that one scene from the Matrix. The difficulty to implementing this is that you’d have to adjust when events happen in accordance to the current timescale, so a punch can’t follow it’s normal timeline for when the hitbox appears, and timeslow could happen while waiting as well.

If animation events are used to determine when a hitbox appears/event happens, you could slow down the animation to have this timeslow effect with little effort, but renderstepped can also be used and doesn’t need an animation track to work. Example:

_G.TimeScale = 1 --//Global
function ScaledWait(TotalDelay)
	local ScaledWaitLoop
	local TimeWaited = 0

	--//Somewhat expensive function, do on client if you can.
	ScaledWaitLoop = game:GetService("RunService").RenderStepped:Connect(function(TimePassed)
		TimeWaited += TimePassed
	end
	--//Stall until enough time has passed.
	repeat task.wait() until TimeWaited >= TotalDelay
end)

This is what I’m trying to do:

the bullets are shot through animations get signal reached events and everything is serversided (animations/effects)

should i make everything client sided and take out the animation events?

Yes, it’ll be more preformant than running it on the server.

1 Like

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