How do I make a GUI appear on the players screen who is seated in a specific chair and when a ProximityPrompt Gets Triggered by another player

Hey, Can anyone help me?

Im having trouble with my code.

I want the gui to only appear on the player who is seated
Can you help?

I’ve tried some solutions but it didn’t work.

Here is my code:

local Passpart = game.Workspace.PassPart
local prox = Passpart.ProximityPrompt

prox.Triggered:Connect(function(plr)
		if plr.Backpack:FindFirstChild("Pasaport") then
			
			print("Pasaport found!")

			local Seat = game.Workspace.SMSEAT

			local function Seated()
				if Seat.Occupant ~= nil then
					
					game.StarterGui["Pasaport Gui"].Passaport.Visible = true

				end
				if Seat.Occupant == nil then
					
					game.StarterGui["Pasaport Gui"].Passaport.Visible = false
					
				end

			end
			Seat:GetPropertyChangedSignal("Occupant"):Connect(Seated)





		else


			print("Pasaport not found")


		end
		
	end)
1 Like
local Passpart = game.Workspace.PassPart
local prox = Passpart.ProximityPrompt

-- It is better to store such variables behind connections
local Seat = workspace.SMSEAT

prox.Triggered:Connect(function(plr)
	if plr.Backpack:FindFirstChild("Pasaport") then
		print("Pasaport found!")

		Seat:GetPropertyChangedSignal("Occupant"):Once(function()
			-- StarterGui is the basis from which players take their Gui when respawning
			-- PlayerGui is a UI repository for each player individually. Every player has it and displays their UI in real time.
			
			local UI = plr.PlayerGui["Pasaport Gui"].Passaport
			
			-- when you enter if Seat.Occupant without using other conditional statements, 
			-- it automatically checks whether the element is nil or false, 
			-- if not then the condition continues if yes, then it is loaded or continues in else if you have one.
			
			if Seat.Occupant then
				-- for example:
				-- UI.Visible = true
				-- not true = false
				-- if not true => if true == false
				-- if not UI.Visible => if UI.Visible == false then UI.Visible = true
				if not UI.Visible then
					UI.Visible = true
				end
				
				-- if true == true then
			elseif UI.Visible then
				UI.Visible = false
			end
		end)
	else
		print("Pasaport not found")
	end
end)

Where do I put this and is it a Local Script?

Did you specify the server script above? If yes, then put it there.

It is currently in ServerScriptService But it doesn’t work I tryed testing it with 2 players and the GUI doesn’t show up

Then replace your code with this

Okay
I will try the code you will send

Have you already tried the code I posted before?

Im currently trying it do i have to edit the code u sent before testing it?

No, you can only remove comments if they bother you.
Also, if the code does not work, show what it outputs to the console.

image
Aren’t we supposed to put something above the ‘’ if not UI.Visible then ‘’

Your code didn’t work and I looked at the output there was nothing there do I need to make the UI visible first to make it work?

image

No, it’s not necessary here. The line below does this.

we check if Seat.Occupant is not equal to nil, then in the next check we check whether our UI is enabled. Elseif fires when Seat.Occupant is nil and turns off the UI.

elseif replaces this with the following construction:

if Seat.Occupant then
	if not UI.Visible then
		UI.Visible = true
	end
else
	if UI.Visible then
		UI.Visible = false
	end
end

Have you looked at the server console? To view it, press F9 during the game

This is the video of me trying it

External Media

The console is empty because you are showing the client side.

Client is everything that is displayed by the player and is subjective to the player.
The server is all you usually see.

That is, the world (workspace). Your script is on the server side, so you can’t see what it outputs on the client. Change the console to a server side.

I would have the script be client.
Have it detect if someone sits or not, and then just display the GUI or hide it depending on when it changes.


still same

Okay but
How can I make that tho?

image
image

local seat = script.Parent
local guiSource = seat:WaitForChild("ScreenGui")
local gui = nil

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	if seat.Occupant then
		local player = game.Players.LocalPlayer
		if gui then 
			gui:Destroy() 
			gui = nil	
		end
		gui = guiSource:Clone()
		gui.Parent = player.PlayerGui
	else
		if gui then 
			gui:Destroy() 
			gui = nil	
		end
	end
end)