How would I go about making one key input do 2 different things?

I wanna make a helmet that opens upon the press of a button and close when it’s pressed again, how would I go about making that?

You can use UserInputService and then just use a boolean variable to get the current toggle.

You don’t say lmao. Thanks anyways.

you could just use a bool to check if its open or not

if IsOpen == true then
    --close helmet
    IsOpen = false
else
    --open helmet
    IsOpen = true
end

I literally said you can use a boolean variable to get the current toggle, everything past there should be self explanitory.

(see ethairo’s post.)

I have to execute this inside the local script with the input functions right?

You need to define a variable with a true or false value (a boolean). When the player inputs, check the current state and run whatever code you need (eg: true = open, false = close).

local isOpen = false -- variable

InputBegan:Connect(function(Input) 
    if Input.whatever == whateverInputYouNeed then
        local newState = not isOpen -- "not" gets the opposite value (not true = false, etc)
        local currentState = isOpen -- get the current state as you are about to change isOpen

        isOpen = newState -- set new state

        if currentState then
            -- close helment
        else
            -- open helmet
        end
    end
end)
1 Like

I wouldn’t recommend using UserInputService as it’s pretty lacking compared to ContextActionService
since it allows for easy compatibility for mobile devices, as soon as the input is detected I’d pass everything to the server to prevent issues with exploiters.

Sorry for the super late reply, been busy with life stuff.

if “not” gets the opposite value and “IsOpen” is false, newstate becomes true then?