How do i make a seat timer

Hello, im trying to make a chair so that when you sit on it a timer starts
and when reaching a certain time a ui text pops up
if you leave the seat the timer resets #

i started with this

local seat = script.Parent
seat.Changed:Connect(function(plr)
	if seat.Occupant then
		
	end
end)

here i edited your script some

sorry about the random indents, devforum doesnt let me indent with tab

thank you

random letter sakjdjks

hi, do you know how to view the timer as a leaderboard status?

Give them a tick or solution

local value = 0
local seat = script.Parent
local loop_running = false
local RemoteEvent = Instance.new("RemoteEvent")

RemoteEvent.Parent = game.ReplicatedStorage

seat.Changed:Connect(function(plr)
	if seat.Occupant then
		loop_running = true
		while value ~= 20 do
			print(value)
			task.wait(1)
			if not loop_running then break end
			value += 1
		end
		RemoteEvent:FireClient(plr, true)
	elseif not seat.Occupant then
		loop_running = false
		value = 0
		RemoteEvent:FireClient(plr, false)
	end
end)

Local Script:

local ScreenGui = script.Parent

if not game.ReplicatedStorage:FindFirstChildOfClass("RemoteEvent") then
	game.ReplicatedStorage:WaitForChild("RemoteEvent").OnClientEvent:Connect(function(bool)
		ScreenGui.Enabled = bool
	end)
else
	game.ReplicatedStorag:FindFirstChildOfClass("RemoteEvent").OnClientEvent:Connect(function(bool)
		ScreenGui.Enabled = bool
	end)
end

Hi, thanks for the script but
a error comes up it says unable to cast value to object on the first script line 17

I’m pretty sure seat.Occupant is the player’s character, run Players:GetPlayerFromCharacter(seat.Occupant) and fire that player, not plr

I made my script too complicated. Try this instead. Insert a ScreenGui, disable it and insert a local script and frame. Paste the following code:

local ScreenGui = script.Parent
local value = 0
local maxValue = 5
local humanoidSeated

game.Players.LocalPlayer.Character:WaitForChild("Humanoid").Seated:Connect(function(active, currentSeatPart)
	print(active)
	if active then
		humanoidSeated = true
		while value ~= maxValue + 1 do
			print(value)
			task.wait(1)
			if not humanoidSeated then break end
			value += 1
		end
		ScreenGui.Enabled = true
	else
		humanoidSeated = false
		value = 0
		ScreenGui.Enabled = false
	end
end)