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

How do I make a GUI appear when a player is sitting on a seat?

Asked by 3 years ago

I want to make a script when someone sits on a seat a GUI will appear, how do I do that?

2 answers

Log in to vote
0
Answered by 3 years ago

hi

plr = game.Players.LocalPlayer
char = plr.Character or plr.CharacterAdded:Wait()

if char.Humanoid.Sit == true then
    urGui.Enabled = true
end
0
i think you need it on disabled if you use friskys way Fxicity 10 — 3y
0
This solution will display the GUI when a player sits on any seat, be aware of that, unless that is what you want. Torren_Mr 334 — 3y
Ad
Log in to vote
0
Answered by
Torren_Mr 334 Moderation Voter
3 years ago

Hello there.

I will provide you with a script. In order to make it work, you need to put the script inside the seat, and the GUI inside the script.

If you have any further questions, feel free to comment or message me.

local seat = script.Parent
local guiName = "TestGui"
local gui = script:WaitForChild(guiName)
local Players = game:GetService("Players")
local lastplr 

-- each time the Occupant property of the seat fires...
seat:GetPropertyChangedSignal("Occupant"):Connect(function()
    if seat.Occupant ~= nil then
        local char = seat.Occupant.Parent
        local player = Players:GetPlayerFromCharacter(char)
        local cloned = gui:Clone()
        -- cloned.TrainName.Value = script.Parent.Parent.Parent.Name
        cloned.Parent = player.PlayerGui
        lastplr = {player, cloned} -- store player and Gui in array
    else 

        print("player left")
        if lastplr then -- verify lastplayer is not nil
        lastplr[2]:Destroy() -- since the table's numerically indexed, we know lastplr[2] will be the Gui
        lastplr = nil
     end
  end
end)

-- Credit for code goes to XxELECTROFUSIONxX

Answer this question