Optimisation on checking inputs

This might seem stupid, because im really tired, but is there any way to not have to write code for checking inputs every time youd want to check for inputs. Kind of like a reverse module script or something. Im worried about using a localscript that fires a remoteevent for every input since it may cause lag or something similar. And i am aware that there probably is a blatant solution to this. Or there isnt any.

You can use User Input Service.

local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input(
   if input == Enum.KeyCode.LeftShift then
      blah blah whatever you wanna do
   end
end

change the left shift gor whatever you wanna detect

1 Like

Thank you for the reply, im looking for a way to only write this once somewhere and have scripts using this one part, instead of having alot of these which iim afraid will cause lag.

1 Like

You may be overthinking it. I think this is the best method to detect inputs and it shouldn’t cause lag.

2 Likes

You can try using the new Input Action system.

Attach your module to a keybind

if Input.KeyCode = EnumKeyCode then
    require(DebugModule).log()
end
1 Like
for i,v in tabledicitonary do
if InputObject.KeyCode=i then v() end
end

Checks if InputObject is same to tabkedictionary’s key name then runs function used as value… (Instances also can be used in table)

It won’t cause lag don’t worry, you can have hundreds of those connections running and have zero performance cost

1 Like

alot is wrong here its insane

dictionary but you use i, v and not k, v
dicitonary ah yes that’s correct fr

anyways:
you can just do tabledictionary[InputObject]() (assuming you validated the method exists)

1 Like