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)
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
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)