How do I make a Gui that pops up only when someone is sat on a seat?

I would like to make my Gui only appear when the character is sat on a seat. How would I do this?

2 Likes

you could use Seat.Occupant, which returns the humanoid of whoever is sitting in it.

There is an event that is already built into Roblox that does this exact thing.

All you just have to do after is tween the GUI on when the player is seated.

1 Like

Hi!

Humanoids have a property called “Seated”, which you can use to get a signal of whenever someone sits or gets out of a seat.

If you want to get when the player seats on ANY seat you can do this in a LocalScript:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")

Humanoid.Seated:Connect(function(seated)
    if seated then
	    --Player seated
    else
	    --Player jumped away
    end
end)

Else if you need to get when a player seats on a specific seat then you can do this:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Seat = --Put here the object reference to the seat

Humanoid.Seated:Connect(function(seated, seat)
    if seated and seat ==  Seat then
	    --Player seated on correct seating
    else
	    --Player jumped away
    end
end)
1 Like

Where do I put the LocalScript?

You could put it in StarterGui or directly into the script that controls the UI.

1 Like

Get the playergui, and if the player is seated enable the UI in the playergui so it only appears for the only player that is seated.

Now that only sees if the player is sitting, how do I make it that the Gui shows when they are sitting?

To make it show the GUI, you add this:

local Player = game.Players.LocalPlayer
local Character = Player.Character
local Humanoid = Character:WaitForChild("Humanoid")
local Seat = --Put here the object reference to the seat
local UI = --Put here the object reference to the ScreenGui

Humanoid.Seated:Connect(function(seated, seat)
    if seated and seat ==  Seat then
	    --Player seated on correct seating
        UI.Enabled = true
    else
	    --Player jumped away
        UI.Enabled = false
    end
end)

If you then want to make it appear like sliding from a direction you can use this on the frame: GuiObject | Roblox Creator Documentation

4 Likes

Hi, it’s not really a good practice to use a .RenderStepped to detect a player sitting, there are roblox core events which are made for this purpose, doing so would just reduce the game performance.

Hey! Maybe change

local Character = Player.Character

to

local Character = Player.Character or Player.CharacterAppearanceLoaded:Wait()

to prevent any errors.

1 Like