Endurance Challenge Scripting

Hey everyone!

I’ve been trying to create this “endurance” type block, such as if it is isn’t clicked in y seconds then x will occur. I understand how to go about the rest of it, but I do not know how to write the code for checking if it hasn’t been clicked.

Anyone got any tips? Does it have to do with events being fired? Thanks in advance.

Heartbeat timer. Use a modified version of this server script;

 local function TIMER_Every500ms()
 	timerCount500ms = timerCount500ms + 1
	if (timerCount500ms == 2 ) then
		TIMER_Every1000ms()
		timerCount500ms = 0
	end 		

	-- things to do every 0.5 seconds
end

local RunService = game:GetService("RunService")
local heartBeatCount = 0
local desiredInterval = 0.5 --fire every .5 seconds
local counter = 0
RunService.Heartbeat:Connect(function(step)
	counter = counter + step  --step is time in seconds since the previous frame
	if counter >= desiredInterval then
	    counter = counter - desiredInterval
		heartBeatCount = heartBeatCount + 1 
		
		if (heartBeatCount == 1) then
			heartBeatCount = 0
			TIMER_Every500ms()
		end
	end
end)

I’ve shown you how to call functions every 500ms or every 1000ms. The rest should be easy.

What I would do to detect if the player had pressed the button is,

  1. Create an int that is always 0
  2. Have the button press add one to that variable
  3. If the variable is 0 then it does the bad command else it does the good command
    If it’s a GUI then put this in your GUI as a localscript.
    I would also suggest loading the Button and then unloading it
    2 Localscripts below:
--script 1
--nsg
--use credit
g=script.Parent.value;g.Value=0;local b=script.Parent.Frame.TextButton;b.MouseButton1Click:connect(function(player)g.Value=1;warn("button pressed goto next stage")end)
--Script 2
--nsg
--credit me
local frame=script.Parent.Countdown;local butt=frame.TextButton;function countdown(player)local countdown1 = {"0","1","2","3","4","5"}script.Parent.Frame.TextButton.Visible = true;for i = 5,0,-1 do
wait(1)script.Parent.Countdown.TextLabel.Text = i;end
if script.Parent.Countdown.TextLabel.Text == "0" then
warn("time is up")if script.Parent.value.Value >= 1 then
warn("Won")else
warn"lost"
end
end
end;butt.MouseButton1Click:connect(countdown)

Here is the loaded obects
image