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

Having trouble with checking if a player presses the "R" key?

I tested the code ingame and it seems like to me it isn't reading when R is pressed.

function onKeyPress(inputObject, gameProcessedEvent)
	if inputObject.KeyCode == Enum.KeyCode.R and highlightstick == false then
		if not game:GetService("MarketplaceService"):UserOwnsGamePassAsync(a.UserId,5815263) and a.Name~="Player1" then
			game:GetService("MarketplaceService"):PromptGamePassPurchase(a,5815263)
		else
			highlightstick = true
			script.Parent.Size = script.Parent.Size.Vector3.new(0,0,0)
			print("worked")
			wait(2)
			highlightstick = false
			script.Parent.Size = script.Parent.Size.Vector3.new(2,4,2)
			print("worked1")
		end
	end
end
 
game:GetService("UserInputService").InputBegan:connect(onKeyPress)

4 comments

0

This script is very complicated to read. It can be more simplified.

0

That doesn't help the problem at hand

0

It doesn't automatically provide both the arguments, that has to be defined manually I believe

0

also :connect is deprecated, use :Connect

1 answer

Hey! I'm BlackOrange and I will be helping you today!

#Problem:# You are copying and pasting the code from the Roblox wiki website which may or may not be compatible.

#Solution:#

Using a local script:

local UIS = game:GetService('UserInputService')

UIS.InputBegan:Connect(function(Input, IsTyping)
	if IsTyping then return end
	if Input.KeyCode == Enum.KeyCode.R then
		print('R has been pressed!')
	end
end)

Now all you have to do is put the code that you wish to use under the print.

Hopefully, this helped.

Best of luck developer!

BlackOrange3343

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