Hello, I’ve been working on some abilities for my game and I need a way to replicate effects to the client instead of having the server do everything.
Right now, I have multiple remote events for each ability to replicate effects on the client (VFX, Particles, etc). I’m looking for any ideas on how I could change properties, use methods, etc. for this as this is becoming costly and less efficient as I continue to update and add new stuff to my game.
local switch:{[string]:(...any)->()} = {
["ability1"] = function():()
end;
["ability2"] = function():()
end;
}
local function _default():() end
AbilityEffects.OnClientEvent:Connect(function(abilityName:string, ...:any):()
(switch[abilityName] or _default)(...)
end)
Is this not just the same as choosing a selected ability and default if it can’t find any? Why the fancy extra code? Sorry, just not familiar with this
Its a big differance.
When you have over 17+ if statements it would produce a ton of instruction meanwhile my example would not have such a problem;
Look how switch statements work in C for example.
Lookups is one of the fastest instruction in luau (as far as I know), where if statement will have to continue executing conditions until it finds the correct one, where it still does the lookup
If you only want to cut down on the amount of remotes, just use if-statements or a networking module like Blink.
Depending on the type of game you’re making. If you’re looking to cut down on lines of code, you can probably handle all VFX within a single script.
You’d want preset values for the emit count, emit delay (how long it waits before emitting from that specific ParticleEmitter), and emit duration (how long you want to keep the ParticleEmitter enabled after initially emitting), probably stored as attributes within the ParticleEmitters themself. Then you’d need to pass info about the particle such as the player and parent whenever you want to actually create VFX.
With this method you’ll probably lose out on a bit of control over things like cancelling VFX (assuming you’re replicating the VFX from the server to the client, you can connect the VFX to an instance and send it with the other info), so it really depends what you’re going for.
You can use BoolValue instances. Toggle them true/false on the server, and set up a GetPropertyChangedSignal on the client. I mostly use RemoteEvents/RemoteFunctions, but sometimes a BoolValue instance is better.