Timer that can reset on button press

Alright so i have a script to stare at a broken watch on button press, it is toggleable

local script btw

I don’t really know where to even start on this but staring at the watch for 10 minutes will give you a badge

how can i script a timer that will reset when i put the watch down

line 21 is putting the watch down and line 15 is putting it up


local character = script.Parent.Parent.Parent

local part = script.Parent
local seat = part.Animation
local input = game:GetService("UserInputService")

local animator = character.Humanoid:WaitForChild("Animator")
local a = animator:LoadAnimation(seat)
local plr = game.Players:GetPlayerFromCharacter(character)
mouse = plr:GetMouse()
local isdo = false
mouse.KeyDown:connect(function(key)
	if key == "q"  then
		if isdo == false then
		a:Play()
			isdo = true
			game.Lighting.DepthOfField.Enabled = true

	
		elseif isdo == true then
			a:Stop()
			isdo = false
			game.Lighting.DepthOfField.Enabled = false

		end
	end
end)
1 Like

You should use UIS.InputBegan. mouse.KeyDown is deprecated and returns a mouse key press or something.

but thats not what i asked!!!1111

I’ll keep that in mind, thank you.

You are trying to check for a key press. User Input Service handles that.

local animator = character.Humanoid:WaitForChild("Animator")
local a = animator:LoadAnimation(seat)
local plr = game.Players:GetPlayerFromCharacter(character)
mouse = plr:GetMouse()
local isdo = false
mouse.KeyDown:connect(function(key)
	if key == "q"  then
		if isdo == false then
			a:Play()
			isdo = true
			game.Lighting.DepthOfField.Enabled = true
			
			-- // Time counter
			local startTime = os.clock()
			while true do
				-- // Check if player pressing Q again.
				if isdo == false then
					break
				end
				-- // 600 seconds = 10 minutes
				if os.clock() - startTime >= 600 then
					-- // Give player badge or something.
					break
				end
				wait()
			end
		elseif isdo == true then
			a:Stop()
			isdo = false
			game.Lighting.DepthOfField.Enabled = false
		end
	end
end)

Here.

1 Like

Or you can do this.

while isdo do
	-- // 600 seconds = 10 minutes
	if os.clock() - startTime >= 600 then
		-- // Give player badge or something.
		break
	end
	wait()
end
1 Like

Thanks homie, very helpful.

This will be fun

1 Like