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

how to use a key to change something in an enviroment?

I'm making a small singleplayer minigame and my lack of knowledge of any coding language has left me unable to make a script that binds the q key to replace a button can anyone help me with this?

2 comments

0

context action service /user input service and a remote event

0

you should read the lua pil and the roblox developer wiki first if you don't know much about the language

1 answer

So if I get this, you want to bind something to Q key, right? Put a local script to StarterCharacterScripts Put this code into it: (This is an example)

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.Q then -- if key is Q
		--Q was pressed, do stuff
	end
end
 
game:GetService("UserInputService").InputBegan:Connect(onKeyPress) -- on input began (see the link what I sent) - connect onKeyPress() function

You can read about UserInputService's InputBegan event there

5 comments

0

pls explain

0

InputBegan is not a function

0

Where you read that? :'D

0

if you aren't using a function twice or more, just making it an anonymous function would be better

0

if you aren't using a function twice or more, just making it an anonymous function would be better

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