Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How do i decrease an int value? And how do i keep repeating this until i want it to stop?

Hello!

I'm making an game with an countdown. I use an IntValue to showcase the value.

And via an gui i show that int value, creating an countdown, etc.

If you dont understand, basicly this.

while true do
	local epic = game.Workspace.TimeCycle.Time.Value -- this is temp here for testing

	script.Parent.Text = (epic)
end

but anyways, i wanna know, how can i subtract value from the int value?

(note, ive seen other posts, but iether i am actually stupid, or the script was specialized)

its hard to explain what i really want. but basicly


local count = script.Time.Value

count = "80"
wait(1)
count = "79"

-- etc

but then in a more efficient way.

the title says it all. Please dont bully me for this. Im new to coding.

Thanks in advance

2 answers

✓ Accepted answer

You can't use strings in int values, also here is how you decrease it:

local count = script.Time--This is a mistake a lot of beginners do, when you set a variable for the .Value you can't change it, the variable is just set to the current value of the .Value

while true do--Sets up a loop
	wait(1)--Waits 1 before subtracting
	count.Value = count.Value - 1--Subtracts 1 from the count.Value, because you want it to equal to it's current value - 1
	
	if count.Value <= 0 then--Checks if it is less than or equal to 0, note that the less than is just a precaution incase something weird happens
		break--Breaks out of the loop
	end

	script.Parent.Text = tostring(count.Value)--Make sure to convert the number to a string before setting the value of any string to a number
end

--Now the count.Value should be equal to 0

Intvalues are always hard to wrap your head around at first, but it will make more sense as you use them more and more.

1 comment

0

Thank you!

An alternative answer to firestarroblox123 is using for loops.

for loops play until it reaches a certain point.

An example:

for i = 30,1,-1 do
	script.Parent.Time.Value = i
	wait(1)
end

Basically, what it's saying is this:

From 30 to 1, subtract 1 from the 30 everytime, do this

I hope I helped! I wish you a merry christmas! :D

This discussion is preserved as it was. New answers, comments, and votes are closed.