#How do I make a GUI pop up when I sit down on a seat

1 messages · Page 1 of 1 (latest)

wheat oar
#

How do I make a GUI pop up when I sit down on a seat just for the person sitting on the seat ;

I put this script under the seat

local Seat = script.Parent -- Seat
local PlayerSitting -- Blank Variable

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
if Seat.Occupant == nil then -- Player Jumped Out
if PlayerSitting ~= nil then -- Player Is In Game (Did not Leave Game)
local PlayerUI = PlayerSitting:WaitForChild("PlayerGui")
local NeededUI = PlayerUI:FindFirstChild("Frame") -- Change this To Your GUI Name
NeededUI.visible = false
PlayerSitting = nil -- Set The Var to nil
end
else -- Someone Sat Down
PlayerSitting = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
local PlayerUI = PlayerSitting:WaitForChild("PlayerGui")
local NeededUI = PlayerUI:FindFirstChild("Frame") -- Change this To Your GUI Name
NeededUI.visble = true
end
end)

(I copied and pasted this script from a developer online I found but this code still does not work)
I tried using the RemoteEvent thing and starterplayerscripts but nothing worked. I can sit on the chair but once I sit nothing happens.

sick hamlet
#

nevermind

burnt nightBOT
#

studio** You are now Level 1! **studio

wheat oar
#

I just found this code from online and tried understanding it but i did not understand and it didnt work

sick hamlet
#
local Seat = script.Parent -- Seat
local PlayerSitting -- Blank Variable

Seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if Seat.Occupant == nil then -- Player Jumped Out
        if PlayerSitting ~= nil then -- Player Is In Game (Did not Leave Game)
            local PlayerUI = PlayerSitting:WaitForChild("PlayerGui")
            local NeededUI = PlayerUI:FindFirstChild("Frame") -- Change this To Your GUI Name
            NeededUI.visible = false
            PlayerSitting = nil -- Set The Var to nil
        end
    else -- Someone Sat Down
        PlayerSitting = game.Players:GetPlayerFromCharacter(Seat.Occupant.Parent)
        local PlayerUI = PlayerSitting:WaitForChild("PlayerGui")
        local NeededUI = PlayerUI:FindFirstChild("Frame") -- Change this To Your GUI Name
        NeededUI.visble = true
    end
end) 
sick hamlet
wheat oar
sick hamlet
#

First, you'd have to get the seat variable and use GetPropertyChangedSignal() method to determine if a player sat on the seat and unseat.
then you'd need to get the player object using players service GetPlayerFromCharacter(). Use if statement to see if player sat or got off the seat. Acquire the playergui, find the frame you wish to open and set it visible/enabled

wheat oar
sick hamlet
#

Script can be placed anywhere else, if you understand object hierarchy.

wheat oar
sick hamlet
#

then put it under the seat

wheat oar
#

ok

wheat oar
sick hamlet
#

read what I stated before