Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to disable Gui when player sits on seat??

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


2 answers

✓ Accepted answer

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)

1 comment

0

It works Thank you so much!!

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


9 comments

0

The code doesn't work no errors very strange

0

Ill try it later in studio

0

ok

0

I know why, ill edit my answer

0

I know why, ill edit my answer

0

ok I'll test in a bit thanks

0

Just tested it still didn't work. There were some errors in the code so I fixed them but still after I fix them it doesn't work and it doesn't have any errors.

0

alr, ill try it later.

0

Sounds good

This discussion is preserved as it was. New answers, comments, and votes are closed.