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

How to add key controls to your car?

Asked by 3 years ago

I'm not talking about the WASD controls, I'm talking about the other controls like blinkers, and other important features.

0
what do you have? kkfilms_1 68 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

https://developer.roblox.com/en-us/api-reference/class/UserInputService

If I were doing it I'd probably do this:

Have a LocalScript in the VehicleSeat, make sure the LocalScript is disabled.

Have a ServerScript in the Vehicle Seat and have it write something like this:

-- serverscript in the vehicleseat.

local Seat = script.Parent
local localScript = Seat.LocalScript

Seat.Changed:Connect(function(p)
    if p == "Occupant" then
        if Seat.Occupant ~= nil then
            localScript.Disabled = false
        else
            localScript.Disabled = true
        end
    end
end)

The Localscript:

-- LocalScript
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(input, gameProcessed)
    if input.UserInputType == Enum.UserInputType.Keyboard then
        if input.KeyCode == Enum.KeyCode.L then
            -- the L key was pressed
            -- code to turn on headlights.
        end
    end
end)
Ad

Answer this question