I want to make a game where there are many “kits” that the player can equip. Each of the kits include some abilities the players can use to fight with. Would I have to individually program each ability, and run if statements to see what the equipped kit is and another if statement to check what move they ran? I feel like there is a better way to do this, but I don’t know how. Please let me know if you have any thoughts how to optimize a script like this!
1 Like
You would have to individually program each ability yes, but to check which kit they have, you could just use an attribute, and to check the move they used is using on client is UIS (User Input Service).
However, for checking on the server, you would have to have the client send data to the server and the server would use such data.
1 Like
My approach to negate the if statements would be to create a table, have each ability be a function in the table, and when any ability is used, just call the function
local functionTable = {}
functionTable.Slap = function(player)
print(“SLAP!”)
end
functionTable.AdditionMan = function(player)
print(“1 + 1 = 2 math man“)
end
Remote.OnClientEvent:Connect(function(player, ability)
if functionTable[ability] then
functionTable[ability](player)
end
end)
sorry for lack of spacing I’m on mobile
1 Like
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.