How do I make a LocalScript search to see if a Button on a ScreenGui is pressed while also sensing if a Key on the player's Keyboard is pressed?

I am working on a Part Placement System and I had it have a Part rotate and switch to look like another part by Players pressing a specific Key on their Keyboard. Although this works, I also made a ScreenGui in which players without a Keyboard could press and the same thing happens (Part rotating and switching to another Part). Does anyone know how to implement this into the LocalScript below at the “elseif” statements to sense a player pressing the letter and also sensing if the Button in the ScreenGui has been pressed? Any help would be appreciated.

SCRIPT (only the portion of the entire script in which I want to add the sensing for the Button has been pressed):

        elseif keyCode == keyCodeEnum.Q then
			placeablePointer = placeablePointer - 1;
			if placeablePointer < 1 then
				placeablePointer = #placeable;
		elseif keyCode == keyCodeEnum.E then
			placeablePointer = placeablePointer + 1;

another note (if you need this information):
The button is under a frame which the frame is under the ScreenGui. Another thing is that this LocalScript is located under StarterCharacterScripts (located under StarterPlayer).

in the script, do

-- Whatever you need to do

of course, don’t literally do Button.MouseButton1Down, ‘Button’ should be a reference to the actual button (wherever that is, script.Parent.Parent.Button or whatever, etc)


Thank you! It works now! :slightly_smiling_face:

1 Like