I was confused yesterday over another certain limitation when firing RemoteEvents (client to server) with an InputObject as a parameter, where InputObjects are one of many things that are always omitted when sent over the network; thankfully I’ve already had experience struggling with this exact same issue regarding other objects and so i was able to figure out that it seems as though i need to refine the InputObject down to the KeyCode or UserInputType to be able to send it;
-- this is on a localscript btw
local function func_onBindFired(actionName,
inputState: Enum.UserInputState, inputObj: InputObject)
RemoteEvent:FireServer(inputState, inputObj)
-- ^ this would fire as inputState, nil (the data within the second parameter is omitted)
RemoteEvent:FireServer(inputState, inputObj.KeyCode)
-- ^ this would fire as inputState, AND the correct KeyCode which is what i just figured out
end
RemoteEvent:FireServer(Enum.UserInputState.Begin, Enum.KeyCode.R)
-- ^ this would fire as inputState AND the correct KeyCode, which is what confused me originally
ContextActionService:BindAction("hi", func_onBindFired, false, Enum.KeyCode.R)
because of this, I would assume that my best bet would be to make a simple function to return a reasonable KeyCode/UserInputType depending on what the InputObject represented? (keep in mind I’ll be sending keyboard + mouse inputs for now but likely multiplatform inputs later)
local function Converter(inputObj: InputObject): (Enum.KeyCode | Enum.UserInputType)
local keycode = inputObj.KeyCode
if keycode == Enum.KeyCode.Unknown
then return inputObj.UserInputType
else return keycode end
end
-- and then the new code would look like the improved version below
local function func_onBindFired(actionName,
inputState: Enum.UserInputState, inputObj: InputObject)
RemoteEvent:FireServer(inputState, Converter(inputObj))
end
is this the correct way I should be doing this? im feel content with this solution as it works for me but i would prefer a second opinion incase i overlooked anything with my Converter function