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.