No gui showing up. Event usage problem

Greetings,

Please help me with my script. I get no errors or warnings. It was supposed to show a GUI when the local player enters the seat, but it doesn’t send the event… What did I do wrong? Please help me. My code is down below:

local player = game:GetService("Players").LocalPlayer

local seat = script.Parent

local PowerOnCarRadioEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarRadio").PowerOnCarRadio

if seat.Occupant.Parent.Name == player.Name then

PowerOnCarRadioEvent:Fire(player)

print(player.Name.. " has entered a driver seat. Event successfully sent, powering on car radio.")

end

Is PowerOnCarRadioEvent a Remote event? Can you go into more detail on what that is?

1 Like

It is a bindable event, since i only want the car radio to be for the local player. The script that must receive the event is also a local script.

I have to mention that this is my first time messing with seats.

It only checks if there’s an occupant once. You have to continuously check to see if there’s an occupant, and then when there is, fire the event, and wait until the occupant gets out of the seat (the local player), then repeat this process.

1 Like

Sorry to ask but, can you please help me with this? I don’t really know how to do it…

wait(1) -- Not required



workspace.Seat.Changed:Connect(function()
	if workspace.Seat.Occupant.Parent.Name == game.Players.LocalPlayer.Name then -- Change this reference to fit your game
		print('Connect fired - ' .. game.Players.LocalPlayer.Name .. " entered Workspace's seat.")
-- Enable car radio gui here
		repeat task.wait() until workspace.Seat.Occupant == nil
			
		-- Disable car radio code here
		
	end
end)

You should use this instead, the Connect event fires when the seat is entered, then you fire the car radio gui event. The script yields (waits) until occupant = nil, then you disable the car radio either using an event, or something else.

Also, the event won’t fire under a part because the LocalScript doesn’t run, itself. Put it under StarterCharacterScripts.

I’ll edit your code to fit it, one moment

1 Like

Thanks a lot! I am going to use it right away.

1 Like
local player = game:GetService("Players").LocalPlayer

local seat = workspace. -- Reference the player's car seat here

local PowerOnCarRadioEvent = game:GetService("ReplicatedStorage"):WaitForChild("CarRadio").PowerOnCarRadio

seat.Changed:Connect(function()
	if seat.Occupant ~= nil then -- Only fire event if you're in the seat
	
	PowerOnCarRadioEvent:Fire(player) -- Make gui appear

	print(player.Name.. " has entered a driver seat. Event successfully sent, powering on car radio.")
		
	repeat wait() until seat.Occupant == nil -- Wait for you to get out of the seat		
		-- Disable the GUI here
	end	
end)

This should be easier to implement.

1 Like

Alright, thanks once again! I will look into it. Can I contact you if I encounter a problem regarding this subject? Thanks again!

You’re welcome! And yes, I can.

Also, why is it a BindableEvent?

1 Like

Oh, because it is an event between two or more local scripts. I had one local script inside the seat and one in the GUI (the GUI is the radio).

As the first person who replied asked, “Is it a RemoteEvent?”, the best way to handle this is to fire a RemoteEvent using :FireServer() from a client and receive the client event call from a script in Workspace or inside of the RemoteEvent. This way, you don’t need to fire a BindableEvent with LocalPlayer, and instead just use :FireServer() itself. If you use this, the client automatically fires the localplayer to the server itself, then you can change the PlayerGui of the player that fired the event, and turning on the GUI.

A much simpler version of this is to simply set the .Visible of the GUI to true from StarterCharacterScripts, and vice versa.

local players = game:GetService("Players")
local player = players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
local humanoid = character:WaitForChild("Humanoid")

local seat = workspace:WaitForChild("Seat")

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		if seat.Occupant == humanoid then
			--Play sound.
		else
			--Stop sound.
		end
	else
		--Stop sound.
	end
end)

Your script is going to error if seat.Occupant is nil.

I see you fixed the issue in the second script.