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)

5 comments
UserInputService will only work in a LocalScript.
When I use UserInputService in a localscript it doesnt even detect me using the keyboard buttons :/
Where is your script located? LocalScripts will only execute if they are located in some specific places.
@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
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.