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

How to find player that pressed button?

Asked by 7 years ago

Hi! In my place I am building a forklift. I want to be able to press R to raise the forklift and F to lower it. I have the player sitting in the seat (seat.Occupant) stored into a variable (Player) but I do not know how to tell if Player presses a key. I am using UserInputService and if one person clicks r or f all forklifts activate. Any idea how to do this?

local Player = script.Parent.VehicleSeat.Occupant

function onKeyPress(inputObject, gameProcessedEvent)
    if inputObject.KeyCode == Enum.KeyCode.R then
        print("Raise")
    elseif inputObject.KeyCode == Enum.KeyCode.F then
        print("Lower")
    end
end

game:GetService("UserInputService").InputBegan:connect(onKeyPress)

1
UserInputService will only work in a LocalScript. M39a9am3R 3210 — 7y
0
When I use UserInputService in a localscript it doesnt even detect me using the keyboard buttons :/ HelloPeople0004 2 — 7y
0
Where is your script located? LocalScripts will only execute if they are located in some specific places. Link150 1355 — 7y
0
@Link150 Ahh, I see. It was in the Forklift model. I was doing some research and it only executes if its in startergui, backpack, or starterpack i believe. Is there anyway to get it to execute when inside the forkllift model perhaps? What I am trying to do is that I get the current player and the player inside the vehicleseat, if both values are equal then when I press R or F it raises and lowers HelloPeople0004 2 — 7y
0
I know how to do all that BUT check to see if the local player presses a key while the script is inside the forklift. HelloPeople0004 2 — 7y

Answer this question