UI not disappearing

I’m trying to make a delete button GUI but it isn’t deleting when I leave the seat, and I’m not sure why.

local Seat = script.Parent
local StarterGUI = game:GetService("StarterGui")
local Players = game:GetService("Players")
local DeleteCarUI = StarterGUI.DeleteCarUI

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = Seat.Occupant 
	local character = humanoid.Parent
	local player = Players:GetPlayerFromCharacter(character)
	DeleteCarUI.Parent = player.PlayerGui
	DeleteCarUI.Enabled = false
	
	if (humanoid) and player:IsInGroup(5896102)then 
		DeleteCarUI.Enabled = true
	elseif
		(humanoid) and player:GetRankInGroup(2855248) >= 18 then
			DeleteCarUI.Enabled = true
		
		if not humanoid then 
			DeleteCarUI.Enabled = false
		end
	end
end)

This is the script that I’ve used to enable/disable the UI when I sit/leave the seat.

2 Likes

StarterGui does nothing. You need to go to PlayerGui. game.Players[Player].PlayerGui

2 Likes

Can you elaborate on that? What do you mean ‘go’ to PlayerGuI?

1 Like

What Avionic said, basically StarterGui just copies the GUIs in there to the player’s PlayerGui. Try this and see if it works.

local Seat = script.Parent
local StarterGUI = game:GetService("StarterGui")
local Players = game:GetService("Players")
local DeleteCarUI = StarterGUI.DeleteCarUI

local playersitting

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
	local humanoid = Seat.Occupant
	if humanoid then
	local character = humanoid.Parent
	local player = Players:GetPlayerFromCharacter(character)
	
	if player then
		playersitting = player
	end
	if (humanoid) and player:IsInGroup(5896102) then
		player.PlayerGui.DeleteCarUI.Enabled = true
	elseif (humanoid) and player:GetRankInGroup(2855248) >= 18 then
		player.PlayerGui.DeleteCarUI.Enabled = true
	end
	elseif not humanoid then
		playersitting.PlayerGui.DeleteCarUI.Enabled = false
		playersitting = nil
	end	
end)
2 Likes

You should be getting the PlayerGui, StarterGui is a service.

local PlayerGui = player:WaitForChild('PlayerGui')
local DeleteCarUI = PlayerGui.DeleteCarUI

Yours and Avionics’ worked fine thanks for all the suggestions guys!

1 Like

This is late, and off-topic probably, but thank you so much for this, I was having so much trouble with a similar thing.

1 Like