Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Help for Keycode (True and False) ?

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)

3 comments

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

0

Use UserInputService:IsKeyDown(Enum.KeyCode.KeyStroke), it returns a Boolean. You could always just do Boolean = (not Boolean) too.

0

That way it'll always flip between true/false.

1 answer

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.