Server to Client function passing

hello devforum :)!
i am currently in a bit of trouble making a fighting game with abilities: i am handling the hitboxes on the server and the visual effects on the client.

my first plan was to communicate to clients with :FireAllClients() and play the effect however you can’t pass functions as arguments, and since the modulescripts that store the ability functions are in ServerStorage i can’t get the function directly from the client by indexing a string.

i have thought of making another folder of module scripts that contain the visual effects so then i can:

get the function directly from the client by indexing a string

but this means i have to make double the instances which is most likely not the most efficent way for readability and handling lag, what do you recommend?

I recommend rethinking the problem. Rather than sending a function, you should only have one function, on the client, since only the client needs to do visuals for anything. So getting the function by indexing a string isn’t actually a bad idea, but of course I don’t know the rest of your setup. If there’s only one or two visual effects, you might even just make separate RemoteEvents for each weapon or whatever. Ultimately, it’s a matter of memory rather than performance, and the impact shouldn’t matter too much.

3 Likes

You could either make one event with the parameters in a table, use multiple events (I don’t personally recommend this one) or divide each code block in one event by recognizing each with a string, for example, FireAllClients(“Effect1”), then the local script checks with an if statement which block to run.

1 Like

how my system works is:

  1. player activates ability
  2. fires remote to the server (to check the player can actually do that ability and didn’t exploit)
  3. server handles hitboxes
  4. server fires all clients to do the visual effects (animations, particles, etc…) --problem

i’m making a class-fighting type of game and each class has 4 abilities so this wouldn’t be useful.

for now i’ll wait to see if there are other alternatives, thanks :D!

You could still have one event define what is being sent (an animation, an effect etc…), so the local script knows what to do.

1 Like

this is what i want to do however i’m worried doubling the modulescripts will impact memory/performance, it also won’t be good for readability and will end up confusing

I’m not sure I understand, why would you need to duplicate the module scripts?

1 Like

hmm, i will actually try this and see if it doesn’t end up being too many lines

due to the modulescripts being stored in serverstorage

You could make the damage and hitboxes only in one module script though, right? The module scripts for each character can pass information with tables, in one of my games I first pass information to the Hitbox module then the damage one, but you could also make them one.

The original module script for character pass the other module the effect information so when the damage fires the effects also follow.

The ModuleScript shouldn’t be in ServerStorage if it is used by LocalScripts. It should be in ReplicatedStorage.

i decided going about this like I said:

i am not going to add too many classes for now but as i add more i’ll try to think of another method