Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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

2 answers

✓ Accepted answer

hi

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

if char.Humanoid.Sit == true then
	urGui.Enabled = true
end

2 comments

0

i think you need it on disabled if you use friskys way

0

This solution will display the GUI when a player sits on any seat, be aware of that, unless that is what you want.

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

This discussion is preserved as it was. New answers, comments, and votes are closed.