Need help with vehicle gui system

I need help creating a script where you can press a button and It will turn on something like a point light attached to a vehicle (you would get a gui when you sit in the vehicle)

basically my problem is that I cant get a button to only preform an action in the vehicle your driving in from a gui button

key notes:
the vehicles will need to be able to be duplicated

You can use the humanoid’s ‘SeatPart’ property to determine the seat a player’s character is sat in (nil if currently not seated), here’s an example script I wrote.

local Game = game
local Script = script
local Players = Game:GetService("Players")
local Player = Players.LocalPlayer
local Character = Player.Character or Player.CharacterAdded:Wait()

local Button = Script.Parent --Script inside button.

local function OnButtonClicked()
	local Humanoid = Character:FindFirstChildOfClass("Humanoid")
	if (not Humanoid) or Humanoid.Health <= 0 then return end --Ignore button click if the player's humanoid is dead.
	local SeatPart = Humanoid.SeatPart
	if not SeatPart then return end --Humanoid is not seated.
	local Vehicle = SeatPart:FindFirstAncestorOfClass("Model") --Reference vehicle from its seat.
	if not Vehicle then return end --You can perform any additional checks if necessary.
	local PointLight --Reference point light from within the vehicle.
	PointLight.Enabled = true
	task.wait(3) --Add a debounce if necessary.
	PointLight.Enabled = false
end

Button.MouseButton1Click:Connect(OnButtonClicked)

It currently only works locally, you’ll need to incorporate a RemoteEvent object if you want the effect to replicate to the server.

2 Likes

where would I put the script? and how would I incorporate it into a script I already have?

1 Like

It’s a local script and

Looks like the script goes in the gui button
@DogeExploder

yeah but I need to know how I would incorporate a script with it

like a button a that changes something I need to add that