Question: Is there a way you can implement different character abilities running on the client-to-server without using too many RemoteEvents? How could I improve the following code I have below?
Here is how my current format for my code is currently looking like. Assume that some of the following that look like is missing is already included. Also assume I have some kind of anticheat that will deny player’s from abusing RemoteEvents.
-- Local Script
-- The local script is in charge of player's keybind and hit detection that requires to be instant.
if UserInput at 'E' keybind then
if playerClass == "projectile" then
-- cast projectile physics
RemoteEvents.CreateProjectile:FireServer(projectileName, "playerProjectile")
RemoteEvents.CastProjectile:FireServer(physicProperties)
if touch projectile then
RemoteEvents.DealDamage:FireServer()
end
elseif playerClass == "laserbeam" then
-- cast hitscan
RemoteEvents.CreateProjectile:FireServer()
elseif etc... then
-- etc...
end
end
-- Server Script
-- This script is in charge of all the remote events that happens from clientToServer.
RemoteEvents.CreateProjectile:OnServerEvent(function(instance, name)
-- Make projectile under name
end)
RemoteEvents.CastProjectile:OnServerEvent(function()
-- local projectile = Look for a projectile made by CreateProjectile
-- castProjectile similarly to client
end)
RemoteEvents.DealDamage:OnServerEvent(function()
-- Apply damage
end)
This is a summary of what my code looks like. Here is what my RemoteEvent looks like. I am planning to put these remote events into their according to usage (ie. clientToServer Folder, serverToClient Folder)
This will for sure be growing into an unmanageable size later on the more I add more classes. To restate, I am asking if there is a better way to organize this so it will become manageable. Some things I am currently doing is finding similarities where I can combine certain RemoteEvents into one, but not all can be combined.