How To turn on car lights serverside by gui?

Hi,
i wanted to make a GUI inside vehicleSeat so i can turn car lights on and off and indicators and so on
but THE ISSUE IS it keeps giving me error and i don’t even know if i should use local SCRIPT or normal server script…

[i know for a fact its regular server script tho…]

and how to make it so when i click turn on lights it turns on car’s lights and everyone can see it in the server? ( i keep trying this for ages but i dont know… someone please help)
also i tried remotes but i have no clue what i KEEP messing UP and even parenting from player and so stuff… so im making this post because i’m out of ideas of what to do, fix…

Code issue i tried:
(and example how i tried to execute but DOESN’T work) help…

script.Parent.MouseButton1Click:Connect(function()
	print("ok code ran")
	local CarRootFolder = script.Parent.Parent.Parent.Parent.Parent.Parent.SedanMain
CarRootFolder.Parent.SedanMain.Lights.fl.Material = Enum.Material.Neon
end)

RobloxStudioBeta_LqZ74EtsJz

1 Like

Use RemoteEvents.

3 Likes

yes, but like how to execute it from the car? not ReplicatedStoarge so i press button it turns on car light and remote event in car

You can access the RepStorage from a localScript that is in the car. You detect the click via the localScript inside the car and then fire a RemoteEvent to a Script which changes the color/turns on the light



game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect()
script.Parent.MouseButton1Click:Connect(function()
	print("ok")
	local CarRootFolder = script.Parent.Parent.Parent.Parent.Parent.Parent.SedanMain
	CarRootFolder.Parent.SedanMain.Lights.fl.Material = Enum.Material.Neon



end)

how?? i dont get these stuff sorry
also this is not in car and also doesnt even work im so confused

Local Script:

local event = game.ReplicatedStorage.RemoteEvent
script.Parent.MouseButton1Click:Connect(function()
   event:FireServer()
end)

Server Script:

local event = game.ReplicatedStorage.RemoteEvent
event.OnServerEvent:Connect(function()
    local CarRootFolder = script.Parent.Parent.Parent.Parent.Parent.Parent.SedanMain
	CarRootFolder.Parent.SedanMain.Lights.fl.Material = Enum.Material.Neon
end)
2 Likes

Hello,
THANKS so much for your help, i learned alot from this thank you!!!
THIS METHOOD WORKS!! however thats not how i planned, lol.
however, how can i make so the RemoteEvent is in the car? but if i do how where will be the script? that changes lights?

2 Likes

You should always place RemoteEvents in ReplicatedStorage. The Script can be placed inside the Model or in ServerScriptService. Of course, Scripts can also run from some other places but these are the most common ones and places you should always use.

2 Likes

Not to be that type of person but I really don’t think you need remotes for this as stated in the initial reply, it really just does seem like you called parent too many times as that error is unique to calling for an object within “game” itself, which likely means you might’ve checked way too far, remotes are great but they aren’t for everything.

2 Likes

Aahhhaa, alright :+1:!! Thanks for the tip so much!

Oh jeez thats somewhat advanced stuff HOWEVER tysm!! I made it work with remote however thanks for teaching me about this :+1:
Thanks for showing me appreciated

1 Like

remotes don’t need to be in replicated, large chunks of vehicle chassis will have a controller remote per vehicle inside the vehicle, and have a ui in the player’s gui detecting when the player sits, when they do and it has the right name, you can get the humanoids seat, and find the remote and do as needed from there.

1 Like

Yeah this is true, but in the most common way they are placed there or copied into it. And as Roblox says: “It is ideal for ModuleScript, RemoteFunction, RemoteEvent and other objects that are useful to both server-side Scripts and client-side LocalScripts”. So why dont use something that is specifically made for it?

but not all local script need to talk to that same remote all of the time, only the one player that is sitting in the seat needs to use the remote, along with, if you have 1 remote in replicated, and all of your cars and all of your players sending to that single one, you have to make the server script check if the car that is being controlled is the right car, along with the right player.

Yeah I agree totally with you. Well the issue would just be that events are dropped when too many are sended by too many players. The player who fired the event is always the first argument when you are connecting an event on the server and detecting the car is also no problem (for example: naming the car as the plr in workspace).
It is always better to have many RemoteEvents than one and I never argued against it.
I only did say that it is common to place RemoteEvents in ReplicatedStorage as it is designed for this. But of course, in some situations placing RemoteEvents in workspace or in a tool is also good, just not good in the most situations

1 Like

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