Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
2

How to disable Gui when player sits on seat??

Asked by 1 year ago

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

Log in to vote
2
Answered by 1 year ago

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)
0
It works Thank you so much!! theking66hayday 841 — 1y
Ad
Log in to vote
0
Answered by 1 year ago
Edited 1 year ago
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


0
The code doesn't work no errors very strange theking66hayday 841 — 1y
0
Ill try it later in studio bittyboy1234 91 — 1y
0
ok theking66hayday 841 — 1y
0
I know why, ill edit my answer bittyboy1234 91 — 1y
View all comments (5 more)
0
I know why, ill edit my answer bittyboy1234 91 — 1y
0
ok I'll test in a bit thanks theking66hayday 841 — 1y
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. theking66hayday 841 — 1y
0
alr, ill try it later. bittyboy1234 91 — 1y
0
Sounds good theking66hayday 841 — 1y

Answer this question