For a long time, I've had this problem:

All of my scripts surrounding my car's functions (horn, headlights, blinkers, taillights, startup chime) were operated from a GUI. When you clicked it, a script would launch that would say 'if this has been clicked and the person is in the DriveSeat then we must play the startup sound/honk the horn/turn on the hazards/whatever else'. The script referred to the sounds, lights, etc as 'game.Workspace.HondaAccordWagon.Etc,etc.' but I realized that, should there be several people driving Honda Accord Wagons in my game, nothing would work properly. Therefore I tried converting those scripts so that they'd refer to the car as 'script.Parent.Parent.Parent', and that, for whatever reason, didn't work. I tried installing some scripts from free models, but the scripts were about impossible to integrate into my car. I ended up on a post on ScriptingHelpers (or maybe it was the DevForum, idk) telling me to use RemoteEvents for this and that and do this and do that. I've no idea how to use RemoteEvents, RemoteFunctions, and the like, so I couldn't have done this properly. I assume that's why the scripts don't work. Are there any obvious errors in the script and/or my mediocre understanding of FE?

LocalScript inside of a RemoteEvent inside my car:

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
		
		HondaAccordWagon.Body.AccordWagonBody.RemoteEvent:FireServer()
	end
end)

Normal script inside of the car's headlight system:

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

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)

Maybe this is worth mentioning: I got the foundation for the scripts off of this ScriptingHelpers post so maybe I'm completely misunderstanding everything they've said in that post??

2 comments

0

Go and learn everything about Remotes. Its not that hard and I used to be bad at it and knew nothing untill I actually tried usin git and now, using it for me is a piece of cake.