Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How to add key controls to your car?

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

1 comment

0

what do you have?

1 answer

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)

This discussion is preserved as it was. New answers, comments, and votes are closed.