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

How do I get keyboard input while sitting in a VehicleSeat?

Asked by 7 years ago

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?

1 answer

Log in to vote
0
Answered by
Async_io 908 Moderation Voter
7 years ago

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)
Ad

Answer this question