How to make a variable with a decreasing number?

Hello im wondering is there a way to make a variable with a decreasing number because i reallly need that for my game

can you please expatiate what you mean?

  1. Please move this to #help-and-feedback:scripting-support

  2. Could you elaborate?

1 Like

I mean like i want a number for example 200 that decreases with -1 i know that i need to make a for loop but how to do it in a variable

local number = 200
for count = number, 0, -1 do
	number = count
	print(number)
end

local function DecreaseNumber(Number)
	for i = Number,0,-1 do
		Number -= 1
		print(Number)
	end
end

DecreaseNumber(200) 

Are you perhaps making a timer? What I think you are looking for is you want a number to decrease with an interval (from decreasing number, I guess?) until 0, which is basically a timer.

If that’s not what you are looking for, explain what you need a “decreasing number” for, or how it should work. Or, you can try the other answers instead.

Otherwise, open this.

Add a variable to hold the amount of time there is, and if you need it, another variable that serves as a setting for when restarting the timer.

local Time_Default = 200
local Time_Left = Time_Default

Then, functions to manage the timer. If you need to run more code while the time ticks, use a coroutine.

local Timer_Status = false -- To disable the timer coroutine.

local function _Timer()
	Timer_Status = true
	
	while (Time_Left >= 1) or (not Timer_Status) do
		task.wait(1)
		Time_Left -= 1
	end

	Timer_Status = false
	print("Timer stopped.")
end

local function Begin_Timer()
	if not Timer_Status then
		coroutine.wrap(_Timer)()
	end
end

local function Stop_Timer()
	If Timer_Status then
		Timer_Status = false
	end
end

local function Reset_Timer()
	Time_Left = Time_Default
end

Please elaborate further, because I have no idea what example to truely show you.

But, here’s one with a .Touched() event:

local number = 0
local part = workspace:WaitForChild("Counter Part")

part.Touched:Connect(function(otherPart)
	number += 1
	print(otherPart.Name)
end)