I'm working on a forklift but I couldn't figure out how to get the user's keyboard input so I could make the forks go up and down. I've been thinking for a while but I can't think of anything that would work. Help please?
UserInputService
is the way to go if you want to check input. You could set a BoolValue in the player that changes when the player is in the forklift, and have the UserInputService read inputs, but only activate anything if the bool is set to true.
USER INPUT SERVICE
UIS, aka UserInputService
is the best way to go. UIS is used in local scripts and can be triggered by InputBegan
, InputEnded
, and InputChanged
.
InputBegan
does as you would think. It will trigger when a button is pushed.
InputEnded
will trigger when a button is released.
InputChanged
will trigger when a button has been changed.
key
is the argument that is provided. This is the key was pushed, ended, changed, etc. Using Enum.KeyCode
we can decipher which key it was.
An example script would be
local forklift = game.Workspace.BoolValue.Value --Grabs the value local uis = game:GetService('UserInputService') --Grabs UIS uis.InputBegan:connect(function(key) --When the input begans if key.KeyCode == Enum.KeyCode.E and forklift then --Compare the key to wanted key --Move forklift end end)