If I 'elaborated on my question' my title would be way too long.

Basically, this scriptinghelpers post tells me that, in order to make car headlights, I must place a RemoteEvent inside the car, a LocalScript in an unspecificed location, and a script inside the car. I've put the LocalScript in the RemoteEvent. It needs to be somewhere in the car because the car is referred to as 'script.Parent.Parent' several times. I can't say 'game.Workspace...' because, should my game get any traction, there will be several people driving the same type of car. RemoteEvents require LocalScripts, don't they? LocalScripts must be in a player to work, right? So, how can I have a RemoteEvent connected to a local script which is inside a car? If that isn't possible, how can I have a RemoteEvent perform its function with a script that is inside of a car? How can I make car headlights with FE?

Here are the scripts, if you need them:

LocalScript:

local player = game:GetService("Players").LocalPlayer
local HondaAccordWagon = script.Parent.Parent.Parent.Parent
local Headlights = script.Parent.Parent.Headlight1
local UIS = game:GetService("UserInputService")

UIS.InputBegan:Connect(function(inputObject)
	if inputObject.KeyCode == Enum.Keycode.L then
		Headlights.HeadlightLight1.Enabled = not Headlights.HeadlightLight1.Enabled
		Headlights.Headlight2.HeadlightLight2.Enabled = not Headlights.Headlight2.HeadlightLight2.Enabled
		
		script.Parent:FireServer()
	end
end)

Normal script:

local HondaAccordWagon = script.Parent.Parent
local headlights = false

HondaAccordWagon.RemoteEvent.OnServerEvent:Connect(function(player)
	HondaAccordWagon.RemoteEvent.OnServerEvent:Connect(function(player)
	headlights = not headlights
	if headlights then
		script.Parent.HeadlightLight1.Enabled = true
		script.Parent.Headlight2.HeadlightLight2.Enabled = true
	else
		script.Parent.Headlight2.HeadlightLight2.Enabled = false
		script.Parent.HeadlightLight1.Enabled = false
	end
	end)

Yes, I stole the scripts from the aforementioned scriptinghelpers post. Do I feel bad at all? Nope.

6 comments

0

a local script HAS to be a child of the player, it will not run if it is in the workspace.

0

yes it will?

0

Okay, great, but I need it to be there because it MUST reference 'script.Parent.Parent' and not 'game.Workspace....' How would I make a set of headlights using FE and by referencing 'script.Parent.Parent' and not 'game.Workspace...."?

0

To make your game future proof: There should be ONE local script in StarterPlayer. There should be ONE Remote event in ReplicatedStorage. Server should know which car player is in, and act accordingly.

0

Sleazel, with your setup, how do I reference the cars?

0

I would need to see your car script, but I assume the driver only is able to switch the lights? So the server should know when driver enter/leaves car. Then you update, lets say a dictionary in module script in server storage, index is the player, value is the car. Once remote event fires, server looks up player in the dictionary and switches lights in car if there is any.