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

So how do i make a when key pressed?

So when key q is pressed i want my tool transparency to change to 1 but when its already at 1 then it and q is pressed then it changes to 0

1 comment

0

Look into UserInputService.

2 answers

Extending on that comment, look into UserInputService.

Here is an example of how its setup:

function onInputEnded(key)
	if key.KeyCode == Enum.KeyCode.Q then
		-- Do stuff
	end
end

game:GetService('UserInputService').InputEnded:Connect(onInputEnded)

This event returns an InputObject as the first parameter. You can use the .KeyCode property to check if the player has pressed a certain key.

As for the toggling of visibility, an easy trick is to use a boolean to check its current state.

3 comments

0

^^^ A perfect answer.

0

Very well agreed, actually helped me as well.

0

thank you, but one more thing. So i made the bool value for toggling visibilty. so do i make another function for when the key was pressed?

you can use else if statement with the transparency

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