I am trying to make an ability that players can use to fight with each other, and I don’t know how to go about this. I want the player to click “1”, then click their mouse where they want the hitbox to be, then I need to server to spawn the damage parts, and the client to render the particle emmitters. How would I do this with 1 remote event. Would I need a different remote event for each different ability, or could I do every ability, like this one in one event. I have programmed it, I just don’t know how to make it efficient if I had like 30 of these for different “kits” and different ability names. Let me know if you need to clarify, I’m tired and my brain is fried.
You could use a single remote, you can have a variable for the chosen ability and pass that into the single remote. Have an array of keycodes as keys and the value being a string with the ability name, in a UserInputService.InputBegan listener you can loop through the keycodes to see if the input’s keycode matches or use the input keycode as a key and check if it exists inside the array. If the keycode does exist inside the array then fire the remote and pass in the ability name. On the server you can implement the logic for that specific ability, you just have to add checks for each ability or you can have an array of functions with ability name as key and function as value then run the function using the ability name passed in from the remote event.
So in the remote event, should I put if Kit == "yapyapyap" then
and then if AbilityType == "Ultimate" then
do stuff and have that for each kit and each ability?
-- CLIENT
local Abilities = {
[Enum.KeyCode.One] = "PrintHello"
}
UserInputService.InputBegan:Connect(function(Input, GameProcessed)
if GameProcessed then return end
local Ability = Abilities[Input.KeyCode]
if Ability then
UseAbility:FireServer(Ability) -- Remove Event
end
end)
-- SERVER
local AbilityFunctions = {
["PrintHello"] = function()
print("Hello")
end,
}
UseAbility.OnServerEvent:Connect(function(Player, Ability)
if AbilityFunctions[Ability] then
AbilityFunctions[Ability]()
end
end)
This is how I would handle it. You could add ifs for each ability but that isn’t efficient.