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

Why isn't my user input service script working?

Asked by
seikkatsu 110
4 years ago
local uis = game:GetService("UserInputService")
uis.InputBegan:Connect(function(input)
    local key = input.KeyCode
    if key == Enum.KeyCode.F then
        print("hmm")
    end
end)

soo here is my script. it's parented to the workspace and it's a local script and i can't see where the error is. could i please get some help?

1 answer

Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

Here's the script.

My apologies for not explaining, in a rush.

function onKeyPress(actionName, userInputState, inputObject)
    if userInputState == Enum.UserInputState.Begin then
        print("R was pressed")
    end
end

game.ContextActionService:BindAction("keyPress", onKeyPress, false, Enum.KeyCode.R)
-- The above line could also been written as:
-- game.ContextActionService:BindAction("keyPress", onKeyPress, false, "r")
0
thanks ill try this in a second and then ill accept your answer seikkatsu 110 — 4y
Ad

Answer this question