Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by
Avi_i 2
5 years ago

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)
0
This script is very complicated to read. It can be more simplified. danglt 185 — 5y
0
That doesn't help the problem at hand Avi_i 2 — 5y
0
It doesn't automatically provide both the arguments, that has to be defined manually I believe Ziffixture 6913 — 5y
0
also :connect is deprecated, use :Connect Ziffixture 6913 — 5y

1 answer

Log in to vote
0
Answered by 5 years ago

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

Ad

Answer this question