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

True and false with UserInputService Enum.KeyCode?

I want to know how to do this with UserInputService (Enum.KeyCode)

If a player presses a specific E for example it a boolvalue will be true. If the player press it again it's false. How would I do this??

1 comment

0

wiki.roblox.com/index.php?title=API:Class/UserInputService

1 answer

✓ Accepted answer

Hello,

Here is the script I've made for you:

local UIS = game:GetService("UserInputService") --Declare UserInputService
local boolean = false

UIS.InputBegan:Connect(function(Input) --Declare event
	local KeyCode = Input.KeyCode --Declare the "KeyCode" part of the input given
	if KeyCode == Enum.KeyCode.E then --Check if the player pressed the letter E (capitals don't matter)
		boolean = not boolean --Makes the boolean the opposite of it's value. Ex. makes it false if it is true, and vice-versa.
	end
end)

1 comment

0

Why did you make a variable for UserInputService if you are only gonna use it once? Seems like a waste of time and memory.

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