Hey everyone, there is some UI in my game that obstructs the view of players when they’re driving a vehicle. Therefore, I am trying to construct a script that disables the UI (this UI is found in StarterGui and is a ScreenGui)
however, it does nothing.
My code:
local seat = workspace.Seat
local gui = game.Players.LocalPlayer.PlayerGui.UI
-- Function to disable the parent GUI when player is seated
local function disableParentGuiWhenSeated()
if seat.Occupant then
gui.Enabled = false
else
gui.Enabled = true
end
end
disableParentGuiWhenSeated()
seat.OccupantChanged:Connect(disableParentGuiWhenSeated)
I think it’s better if this script is placed inside the UI itself. Meaning that script.Parent will be the gui variable also ensure it’s a LocalScript. Using design techniques like this often minimizes some annoying errors related to replication, player resetting, UI loading, and such.