Writing Input Scripts

I want to centralize all of my controls into one local script. As far as I’m concerned, it would end up looking something like this:

UserInputService.InputBegan:Connect(function(input)
    if input.Keycode == Enum.Keycode.Q then
        -- Do stuff here bound to Q

    else if input.Keycode == Enum.Keycode.E then
        -- Do stuff here bound to E

    else if input.UserInputType == Enum.UserInputType.MouseButton1 then
        -- Do stuff here bound to left click
        -- Follow similar pattern for any other controls

    end
end)

I am, however, a little concerned about any problems with just chaining everything through an if-else-if statement. One that I’ve thought of is whether or not the different types of inputs–namely whether or not it ends up being KeyCode or UserInputType–would cause issues when checking for the conditions. Is this a valid concern? Are there other considerations I should make before chaining everything into a single if-else-if statement?

Also, is this the most optimal way to actually do this? How do you guys format your input scripts?

I say two weeks is a long enough period of no responses to say that this is something I should decide based on my own preferences. If anyone happens to stumble upon this post, yes, it does work.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.