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.
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)