Stopping a Remote Event from Firing

Hello there!
I have a script that detects when you sit down, then fires a remote event to all clients, and makes a screen gui appear. This works, however, when the player gets off of the seat, the gui is still there. How can I disable the gui in a way where it can still be used over again if the player sits back down?
Here’s the script in the seat:

local Players = game:GetService("Players")
local seat = script.Parent
local replicatedStorage = game:GetService("ReplicatedStorage")
local remoteEvent = replicatedStorage:WaitForChild("RemoteEvent")

local currentPlayer = nil

seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = seat.Occupant 
	if humanoid then 
		local character = humanoid.Parent
		local player = Players:GetPlayerFromCharacter(character)
		if player then 
			print(player.Name.." has sat down")
			currentPlayer = player
			remoteEvent:FireAllClients() 
			return
		end	
	end
	if currentPlayer then 
		game.StarterGui.ScreenGui.Enabled = false
		print(currentPlayer.Name.." has got up")
		currentPlayer = nil
	end
end)

This is also a one player game, so I just chose fire all clients to make it easier.

Fire ANOTHER remote event that hides the UI when the player gets off the chair. The events will then togle the UI back and forth.

Instead of making another remote, you can pass an argument in RemoteEvent:FireAllClients() to tell the client whether to show or hide the GUI.

1 Like

Yes, you could use an enabled parameter and set the GUI to that value and simply pass true or false.