Initation before skill on client-sided magic system

NOTE: THE SERVER ONLY HANDLES DAMAGE, CHECKS, AND FIRING TO OTHER CLIENTS

So basically, I’m making use of AnimationTrack.KeyframeReached:Wait() to give skills a startup time. I want a player to press a button once, animation starts, they reach the end of the startup, skill plays.

The issue is, this seems to only be possible if I play the animation on ALL clients. It looks choppy and isn’t very efficient.

Input → Play skill on player client and fire to server at same time → fire to all non-caster clients → those clients play the skill function → KeyframeReached:Wait() → skill continues.

Hit detection handled on caster’s client.

I’ve tried creating an initiation value on server (parented to the caster character), and deleting it on client so that other clients can detect that instead. No errors, didn’t work because I cast the skill on player client first- I think.

Looking for either alternatives or solutions.

My code all functions properly, so the issue is with my design of this system in the first.

2 Likes

I would suggest you only play the animation locally (not allowing it to replicate) if you want the appropriate animations and actions to sync up on clients in that way. Since animations in characters will attempt to replicate, unfortunately the only way to easily stop that is from those other clients, detailed in this post:

1 Like

I know that I should only play animations locally. That’s exactly what the issue is. How can I delay the skills on other clients, if the delay is dependant on a locally-played animation?

If you’re not playing the animation on any of the other clients, I suppose just have a remote from the server start a delayed function on the other clients. Assuming the animation speed is constant, the animation will take a set amount of time to reach that keyframe.

Can I use keyframereached on server??

You should be able to- the animation started on the client would still be replicated to the server so long as it’s in the character.

But a unexpected benefit of this is that you could have the client send the exact time at which to trigger the event for perfect synchronization across clients.

2 Likes

I’ll try this! If it works, I’ll mark it as the solution. Thanks~

If you’re loading the animation using the Animator instance then that will need to be created on the server otherwise the animations will not replicate to the server when played locally.

1 Like

Side note to this, you can also have each client handle their own animations respectively. You just have a RemoteEvent call inform the other clients that you are performing a move. In this call you can include workspace:GetServerTimeNow() as a parameter to make sure that all the clients are in sync.

Then on the other clients, you can call workspace:GetServerTimeNow(), take the offset of the two, and then update the timing in your animation accordingly.

2 Likes