I’m currently creating an rpg project that will have tons of weapons, each having different swing-speed and animation. Right now the way I do is like this:
Client sends request for an attack.
Server receives and verifies it. Server then grabs information about swing-speed/animation that must be played for the weapon that player uses. Then it fires event to the client that plays the required animation, meanwhile the server manages swing-speed by simple task.wait() before the hitbox appearance.
The problem with this method is that I have to manually write swing-speed for each weapon, and that if player has high ping his animation could not correspond to his actual swing timing. I’d like to use Animation Events instead, but then I’ll have to fire animations on the server because they would respond for swing-speed, and I don’t want that to be exploited.
What should I do in this situation? Would it be okay to simply use Animation Event and write animations on the server completely, or there’s some other way that’d be more optimized-but-simple?
Here are solutions that may help: Solution for first problem:
You should use attributes for each sword or modules that keep the swords’ swing speeds and animations. Solution for second problem:
Maybe you should run all animations, damage and sounds on server, maybe camera stuff should be on client.
I’d honestly recommend just running the animation on the client before you even send a request to the server. That way the animation is at least responsive.
Then you can handle the rest of the validication and other stuff on the server THEN you can run the animation on the server for everyone else to see
Correction: nvm if you run an animation for the player on the client, it replicates to the server automatically
You don’t need the server to get the swords’ info.
I recommend putting the combat system script in StarterCharacterScripts (StarterPlayer.StarterCharacterScripts)
Just play and damage the player on the client first (damage only visible on client)
While that, also request damage and animation to server to make it visible to all other players
I thought about something like this, but it would be problematic to insert because I’ll have to replicate all the verifications for receiving damage (if victim blocks, parries, is in dodge etc), aswell as hitboxes on the client. Even if it’s only visual damage, it would still require all these checks to visualise everything properly. I’m also unsure on how it would work out. If player sees his own attack (and the result of this attack) immediately, but other players (who are supposed to react on this attack) see it with ping delay, wouldn’t it be quite confusing? For example, if player 1 hits player 2 and player 2 is not in block, he receives damage for player 1’s client, meanwhile after 0.1 second all of that replicates on the server, player 2 reacts on an attack and blocks it for himself on server-side. I’m really unsure how this will work out.
The thing I’m asking is how bad playing animations on server would be for the game? Is it really that unbearable?
The thing I’m asking is how bad playing animations on server would be for the game? Is it really that unbearable?
IIRC The way server replicates animations is different than replicating something else.
Imagine you have a part, and on server you lerp the part from point A to point B, each that inbetween point gets replicated, which can become unperformant.
But with animations, client plays animation, replicates to server, server tells other players to START playing the same animation, doesn’t replicate each body part CFrame change, etc.
It’s just giving each client an order to begin animation.
Cause if you think about it, playing it on the client still makes server replicate it.