The relevant part for the server side is
local function AttachBindings(self, character)
for _, bindingEvent in ipairs(Constants.BindingEvents) do
local bindings = self.KeyBindings[bindingEvent]
if bindings then
local bindingRemote = ReplicatedStorage.RemoteEvents.BindingRemote
local player = game.Players:GetPlayerFromCharacter(character)
bindingRemote:FireClient(player, bindingEvent, self.Handler, false, unpack(bindings))
end
end
end
where Constants.BindingEvents is just a table of event names, self.KeyBindings[bindingEvent] is accessing my current ‘object’ to retrieve a table with the keybindings for the given bindingEvent (a string), and self.Handler is the function I pass in to handle events.
The current value for self.KeyBinding that I’m testing with is
{
Primary = {Enum.UserInputType.MouseButton1, Enum.KeyCode.F}
}
and the action handler for self.Handler is
function(actionName, inputState, inputObject)
if actionName == "Primary" then
if inputState == Enum.UserInputState.Begin then
print("Handler called")
print(inputObject)
end
end
end
and due to the error that this function ends up nil when entering my LocalScript, those statements are not printing.
For the client side, my entire script is
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local ContextActionService = game:GetService("ContextActionService")
local bindingRemote = ReplicatedStorage.RemoteEvents.BindingRemote
local function bindKeys(actionName, functionToBind, createTouchButton, ...)
ContextActionService:BindAction(actionName, functionToBind, createTouchButton, ...)
end
bindingRemote.OnClientEvent:Connect(bindKeys)