I have been more than once, clearly instructed and incentivized to under absolutely no circumstances, send any instances through remotes, be it Server -> Client or Client -> Server, for several different reasons which I could go on about.
However, upon experimenting with a new weapon system, I hit a roadblock.
Using server for hit detection is really bad, since it has a noticeable delay during gameplay.
Therefore I did some research, and found that most games use client detection and then just validate it on the server.
Fair. Easily done.
However, fixing one problem brings another to light:
How to let the server know which players have been hit in the first place, so that it can propetly validate the interaction?
After some more research, I found that there are examples for what I’m looking in Roblox’s tutorial studio games. More specifically, “Laser Tag”. Upon reading its code, I have come to the realization that in that game, an official Roblox example, they send not just one, but more than one instance through a remote from the client to the server!
Here is a snippet of the code I found:
local function onShootEvent(
player: Player,
timestamp: number,
blaster: Tool,
origin: CFrame,
tagged: { [string]: Humanoid }
)
-- Rest of the code...
From my understaning, in said tutorial game, what is done is:
The client makes the detection of what was hit and what wasn’t based on Player input using SphereCasts, and then makes a list of what players have been hit. It then sends the server all the humanoids that the client hit, with the additional information of where was the shot taken from (the origin position).
Based on that, the server then validates if the shot is possible, and if the tagged player has truly been hit using a distance check.
This is all very nice and reasonably doable, yeah. The problem here is not inherently the structure they have come up with, but instead that after so long being told that instances should never be sent through remotes, upon seeing it in an official Roblox example, I’m confused to whether this is the correct approach or not.
Now, if I ask myself: “Let’s suppose we don’t use humanoids then. Let’s use UserIds”. If that was the case, then another problem arises. You won’t be able to hit anything that has no UserId, such as an NPC.
So what gives? For a system such as this, UserIds? Humanoids?
After all, instances through remotes OR NOT?! And if so, WHEN?