I’m making a game where players have abilities that they can activate with their keyboard, aim with their mouse, etc. I get the input using an AGF controller (local modulescript that is loaded upon player joining game) and send it to the server. The set of abilities that players may have greatly varies, so I want to separate each set into it’s own controller.
I want players to only have the controller for the set of abilities that they own – for example, if a player has fire abilities, they will only have the controller that gets input for fire-related abilities and not the one that gets input for the water abilities.
However due to the nature of AGF, I don’t think I am able to add and remove controllers while a player is ingame. So how would I give the appropriate controller to a player upon loading their data?
First of all, server side and client side connections are key, if you want to check if a player has something, check from the server side and send it back to the client side.
This might work for you:
-- Service
local Service = {Client = {}}
function Service.Client:HasItem(plr, name)
-- Check if the player has the item
return true -- Then return it back
end
return Service
-- Controller
local Controller = {}
function Controller:Start()
local userInputService = game:GetService("UserInputService")
local service = self.Services.Service -- Whatever the name is, replace Service with it.
local controls = {}
if(service:HasItem("Rocket Smash")) then -- For example
controls["Rocket Smash"] = true
end
userInputService.InputBegan:connect(input, gameProcessedEvent)
if(input.UserInputType == Enum.UserInputType.Keyboard and
controls["Rocket Smash"]) then
print("Rocket.... SMASH!")
end
end
end
return Controller
Sorry I got confused about what this was because I didn’t read it. I didn’t mean to send the link of a Datastore caching module. Still, there shouldn’t be much insecurities, but make sure to check if a player has an ability on the server side before you do anything, that way the client can’t interfere and get anything they want.
I’d like to mention that AeroGameFramework has a premade UserInput controller that can make it cleaner and easier to work with user input
local Keyboard = self.Controllers.UserInput:Get("Keyboard")
Keyboard.KeyDown:Connect(function(keyCode)
if keyCode == Enum.KeyCode.E then
-- Yada yada yada
end
end)
You can then:
Skip checking for GameProcessedEvent as that is handled by the UserInput controller
Skip checking for UserInputType since that is handled by the returned Keyboard module
Also use some premade functions that might come in handy: Keyboard:IsDown(keyCode), Keyboard:AreAllDown(keyCodes...),Keyboard:AreAnyDown(keyCodes...)