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 2 years 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:

01local seat = script.Parent
02 
03local PreviousHumanoid = nil
04 
05 
06 
07local function Sat()
08 
09    local Humanoid = seat.Occupant
10 
11    if (Humanoid ~= nil) then
12 
13 
14 
15        PreviousHumanoid = Humanoid
View all 31 lines...

2 answers

Log in to vote
2
Answered by 2 years ago

Check if Seat.Occupant has a value when it is changed.

01local seat = script.Parent
02local Players = game:GetService("Players")
03 
04local previousHumanoid
05 
06seat:GetPropertyChangedSignal("Occupant"):Connect(function()
07    local newHumanoid = seat.Occupant
08    if (newHumanoid ~= nil) and (newHumanoid:IsA("Humanoid")) then
09        local player = Players:GetPlayerFromCharacter(newHumanoid.Parent)
10        if player ~= nil then
11            player.PlayerGui.JobChange.Enabled = false
12            previousHumanoid = newHumanoid
13        end
14    else
15        if (previousHumanoid ~= nil) and (previousHumanoid:IsA("Humanoid")) then
View all 23 lines...
0
It works Thank you so much!! theking66hayday 841 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago
01players = game:GetService("Players")
02local seat = script.Parent
03 
04local PreviousHumanoid = nil
05 
06 
07 
08function Sat()
09 
10    local Humanoid = seat.Occupant
11 
12    if (Humanoid ~= nil) then
13 
14 
15 
View all 34 lines...
0
The code doesn't work no errors very strange theking66hayday 841 — 2y
0
Ill try it later in studio bittyboy1234 91 — 2y
0
ok theking66hayday 841 — 2y
0
I know why, ill edit my answer bittyboy1234 91 — 2y
View all comments (5 more)
0
I know why, ill edit my answer bittyboy1234 91 — 2y
0
ok I'll test in a bit thanks theking66hayday 841 — 2y
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 — 2y
0
alr, ill try it later. bittyboy1234 91 — 2y
0
Sounds good theking66hayday 841 — 2y

Answer this question