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

Trying to make a GUI appear when the Localplayer is sitting down?

Hello, I am trying to make a GUI appear when the Localplayer is sitting down. I currently have the Localscript placed in the frame of the GUI. So I am trying to make it so when it detects that the player is sitting down it will make the frame visible. I've tried writing a script that does this but doesn't seem to work. it doesn't even display any errors it just doesn't work.

Here is the script

wait(3)
local w = game.Players.LocalPlayer.Character.Humanoid
local d = game.Players.LocalPlayer.PlayerGui.work.Frame
---------------------------------------------
if w.Sit == true then
	d = true
elseif w.Sit == false then
	d.Visible = false
end

Can anyone help

1 answer

✓ Accepted answer

If this is a seat you're attempting to sit in, It'd go like this

-- Regular Script inside of the seat

players = game:GetService("Players")
seat = script.Parent
active = false
plr = nil

seat.ChildAdded:Connect(function(child) -- event for the seat
	if not active then -- ensuring this check is false if they are standing
		if child.Name == "SeatWeld" then -- finding the weld
			active = true
			plr = players:GetPlayerFromCharacter(child.Part1.Parent)
			if plr ~= nil then -- ensuring its a player
				plr:WaitForChild("PlayerGui").work.Frame.Visible = true -- your result
			end
		end
	end
end)

seat.ChildRemoved:Connect(function(child)
	if child.Name == "SeatWeld" then
		if active == true then
			active = false
			wait()
			plr:WaitForChild("PlayerGui").work.Frame.Visible = false
		end
	end
end)

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