I am currently in development of an extensive fighting game. I am trying to learn as much as possible on the topic of netcode. I am a little lost, so here are some of my questions, thanks for helping me out!
1: Should hitboxes be done on the client or server?
2: Should movement be done on the client or server, and if on the client, how should I go about replicating positions to all other clients?
3: Do animations usually replicate? I know for most cases they do but sometimes they do not work.
4: How should I go about changing values based on client to client interactions? For instance, I have a modulescript that hands out default player values every time a character dies, respawns, or joins the server. I am guessing I should probably use a remoteevent or UnreliableRemoteEvent for changing values, or change values (on the server) based on events that happen from the client, registered on the server.
Hitboxes should usually be done on the client, especially for fighting games. Then use the server as validation
Movement should always be done on the client, even roblox does. To replicate, have each client send their position to the server, validate it if you want, then the server sends this position to every other client. You should do this about every 0.1s and then let each client interpolate and smooth out the position based on speed and direction in between each interval
Yes, you’d have the server change values and, if these values are stored in a module script, replicate it to the client with a reliable remote event
If you’re using humanoids for your player characters, this is pointless. Roblox replicates from client to server the position of parts the player has NetworkOwnership of. This means it sets the client as the source of truth for physics related things, including position, rotation and collisions.
This is also related to the reason why animations played on the client’s humanoid replicate to other players. I recommend giving the documentation a read as it also goes over how hitbox extender exploits ocurr.
So in this case, I do not have to fire all clients to animate a character, I can just animate the character and it wont have load on the server?
Same with physics related scripts?
yes, local animations are replicated, and things like physics constraints and mover objects (which you will probably use for knockback and hitstun) all work on the client. The object itself wouldn’t be replicated to the server, but since rotation and position is, it doesn’t really matter
See, this is my issue. I will not use (atleast, for the most part) constaints and mover objects. I literally do all of my movement from scratch. But I assume I wont have to worry about this replicating since you said player movement replicates to server.
EDIT: Probably should clarify that this means even if you just edit the cframe directly from the client, not that you’re restricted to use Humanoid:Move() or anything like that.
Sorry about the extra question but since hitboxes are on the client, how should I go about moving these guys? Should I just launch or do linearvelocity changes on my client and it will replicate or what?
My thinking:
hitbox spawns on client → detect if hit → if hit then → launch target on client or server? If Player1 Hits Player2 on Player1’s screen, should the server manage Player2’s trajectory? Or should I launch Player2’s trajectory on Player1’s client instance? I am assuming I should manage Player2’s trajectory on the server…
By the way, I will be editing AssemblyLinearVelocity directly. I probably already stated this but I wont be using BV or mover constraints
should probably do it on the server, otherwise you’re gonna be delayed by both player1’s and player2’s network latency until the trajectory finally registers and replicates.