Destroy GUI if not in group

Hi, how do I make it so that if someone sits in a seat and a car driving controls GUI pops up and they aren’t in the group, it automatically destroys it

https://developer.roblox.com/en-us/api-reference/function/Player/IsInGroup

2 Likes

Hi!
Sorry for my English, I use translator
To track what the player is sitting on, we simply get an RBXScriptSignal bound to a change in the “Occupant” value, using the GetPropertyChangedSignal instance object method

To find out if a player is present in any group, there is a player-IsInGroup method (Player | Roblox Creator Documentation).

All that remains is to get to your GUI and cold-bloodedly ELIMINATE it by deleting it using the Instance :Destroy () object method.

local YourSeat = nil --- Your Seat
local GroupId = nil --- Your Group
local Gui = nil ---Your Gui
YourSeat:GetPropertyChangedSignal("Occupant"):Connect(function(Player)
	if not game.Players.LocalPlayer:IsInGroup(GroupId) then
		if game.Players:GetPlayerFromCharacter(YourSeat.Occupant.Parent) and game.Players:GetPlayerFromCharacter(YourSeat.Occupant.Parent) == game.Players.LocalPlayer then
			Gui:Destroy()---Haha!
		end
	end
end)