Hi I am wanting to remove some of the Gui when a player sits on a seat. There are no errors with the code. The code doesn't work either. JobChange is the Gui I am wanting to disable when the player sits in seat and re enable it when they aren't sitting in seat. Script:
local seat = script.Parent local PreviousHumanoid = nil local function Sat() local Humanoid = seat.Occupant if (Humanoid ~= nil) then PreviousHumanoid = Humanoid script.Parent.Parent.Parent.Parent.Parent.StarterGui.JobChange.Enabled = false end end if (PreviousHumanoid.Parent == nil) then return end Humanoid = PreviousHumanoid script.Parent.Parent.Parent.Parent.Parent.StarterGui.JobChange.Enabled = true
Check if Seat.Occupant
has a value when it is changed.
local seat = script.Parent local Players = game:GetService("Players") local previousHumanoid seat:GetPropertyChangedSignal("Occupant"):Connect(function() local newHumanoid = seat.Occupant if (newHumanoid ~= nil) and (newHumanoid:IsA("Humanoid")) then local player = Players:GetPlayerFromCharacter(newHumanoid.Parent) if player ~= nil then player.PlayerGui.JobChange.Enabled = false previousHumanoid = newHumanoid end else if (previousHumanoid ~= nil) and (previousHumanoid:IsA("Humanoid")) then local player = Players:GetPlayerFromCharacter(previousHumanoid.Parent) if player ~= nil then player.PlayerGui.JobChange.Enabled = true previousHumanoid = nil end end end end)
players = game:GetService("Players") local seat = script.Parent local PreviousHumanoid = nil function Sat() local Humanoid = seat.Occupant if (Humanoid ~= nil) then PreviousHumanoid = Humanoid local plr = players:GetPlayerFromCharacter(Humanoid.Parent) plr.PlayerGui.JobChange.Enabled = false end end while wait() do sat() if (PreviousHumanoid.Parent == nil) then return end Humanoid = PreviousHumanoid local plr = players:GetPlayerFromCharacter(Humanoid.Parent) plr.PlayerGui.JobChange.Enabled = true