Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Help for Keycode (True and False) ?

Asked by 6 years ago
Edited 6 years ago

I have a problem it's when I want (example: If someone presses on E and well it goes in true and if he press again it's become then false)

Bool = true

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.Tab then
        print(true)
        Bool = false
        print(false)
    end
end

game:GetService('UserInputService').InputBegan:connect(onKeyPress)
0
this is a help site, not a code giving site. try to do it yourself and if you cant then post your script and well see what the error is deerdharok 91 — 6y
0
Use UserInputService:IsKeyDown(Enum.KeyCode.KeyStroke), it returns a Boolean. You could always just do Boolean = (not Boolean) too. Ziffixture 6913 — 5y
0
That way it'll always flip between true/false. Ziffixture 6913 — 5y

1 answer

Log in to vote
0
Answered by 6 years ago

Simple, with your current code, add a few lines.

```lua local Bool = true

function onKeyPress(inputObject, gameProcessedEvent) if inputObject.KeyCode == Enum.KeyCode.Tab then -- you said E not tab idk if you actually wrote this code if Bool == true then Bool = false print('False') else Bool = true print('True') end end end

game:GetService('UserInputService').InputBegan:connect(onKeyPress) ``` I'm not sure if you actually wrote this code, if you did you should know about if statements and setting values to different values. Don't steal from others, instead, learn.

-- Your orange, BlackOrange3343

Ad

Answer this question