Vehicle Script Help

Can somebody help me with this script please

local BlinkersEvent = script.Parent.Blinkers
local LeftTurnSignal = script.Parent.LTS
local RightTurnSignal = script.Parent.RTS
local UserInputService = game:GetService("UserInputService")
local DriverSeat = script.Parent.Parent.Parent.DriveSeat

local function LTS()
	LeftTurnSignal.Transparency = 0
	wait(1)
	LeftTurnSignal.Transparency = 1
end

local function RTS()
	RightTurnSignal.Transparency = 0
	wait(1)
	RightTurnSignal.Transparency = 1
end

local function Hazards()
	LeftTurnSignal.Transparency = 0
	RightTurnSignal.Transparency = 0
	wait(1)
	LeftTurnSignal.Transparency = 1
	RightTurnSignal.Transparency = 1
end

UserInputService.InputBegan:Connect(function(input, gameProcessedEvent)
	print("Input began:", input.KeyCode)
	if not gameProcessedEvent then
		if input.KeyCode == Enum.KeyCode.Q then
			LTS()
		elseif input.KeyCode == Enum.KeyCode.E then
			RTS()
		elseif input.KeyCode == Enum.KeyCode.X then
			Hazards()
		end
	end
end)
1 Like

what exactly do you need help with?

I can’t get it to work, The parts don’t change

did you try printing inside of the functions? lmk what the console says afterwards

It doesn’t print, and I don’t get any errors

where’s the script located? is it a server or local script?

It’s located in a folder with all the vehicle lights, and it’s a local script, I’ve tried a server script and that didn’t work either

Specify what exactly the problem is, what you want to achieve and what the result is.

yeah but is the folder inside of workspace, or in player scripts or what?

Alright so by using the UserInputService in a local script that is inside of the workspace. It is simply not going to run. I saw this in another post:

“ A LocalScript will only run Lua code if it is a descendant of one of the following objects:

  • A Player’s Backpack , such as a child of a Tool
  • A Player’s character model
  • A Player’s PlayerGui
  • A Player’s PlayerScripts .
  • The ReplicatedFirst service”

No, The folder in inside the Vehicle Model

Is it inside of workspace or??? Local scripts do not work if they are a descendant of workspace

I’ve tried using a Server Script with it too and it still doesn’t work

That’s because you cannot use User Input Service on server, put the script inside of a local area such as player scripts, and handle it from there.

UIS is something that detects inputs on the client, server is not the same as client.

You can’t put local scripts into a direct descendant of workspace, such as Charles said.

Hey Connor,
as @LuaCoold already said, you cannot run the local script in workspace or any instance in the workspace. Additionally, UserInputService does not work in a server script.

In order to make your script work, you can do the following:

  1. Create a remote event and place it into the replicated storage and give it a name such as „ControlCarRemote“
  2. Replace the local script in the folder with a server script
  3. Add a local script in „StarterCharacterScripts“
  4. Remove the „UserInputService“ part of the server script and add it into the local script.
  5. Instead of calling a function in the local script, you will send a value to the server with the remote event.
    For instance: controlCarRemote:FireServer(„LTS“) — if you press Q
  6. Receive the value with the server script and call the correct function based on the sent value

Please reply back if you have trouble.

I got it working via. RemoteEvent.

Thanks guys!

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.