Numbers going up, help?

@twinqle
@nooneisback
well if for i loops is the only option, I’ll do it. Thanks!

(post withdrawn by author, will be automatically deleted in 1 hour unless flagged)

What exactly is the reason you want to avoid loops though?

What other option would you be looking for…?
Is there something you need that for loops can’t do?

because I don’t know the math to make it go faster or slower according to the amount of times it should repeat
@twinqle

What do you mean exactly? Just multiply the amount.

Do you mean that for certain intervals you want the amount that is added to change?

If you’re trying to recreate the original video:

local count = 0
for i = 1,10000 do
count = count + 1
end

pretend you got a score of 10, it would go up slower than if you were to have a score of 100. it’s like tweening a UI, but with numbers.
with a sine effect

Sort of, but I want it to be as smooth as possible

Oh. You’re saying that as you get closer to the ending of the count, you want it to increase slower?

slower 30characters yay done!!

local goal = 30
local count = 0
for i = 1,goal do
count = count + 1
wait(i/goal)
end

I’m currently on my phone, that’s just a guess of the algorithm you’ll need to use. See if that works.

1 Like

it does get slower, but the start is a bit too slow, how can i increase the speed at the beginning

I added a delay by subtracting .7 from the value.

local goal = 30
local count = 0
for i = 1,goal do
count = count + 1
wait(i/goal - .7)
end

Here’s the result: https://gyazo.com/b150b738dad3675fc1b40df20d16184f
Counting.rbxl (20.4 KB)

1 Like

ok, thank you! I’ll divide instead of subtracting(I think it’s more efficient? maybe?)

1 Like

I’m honestly not sure, math isn’t my strong suit. :man_shrugging:
Good luck!

1 Like

You could use an easing formula!

Here’s an example of what that would look like

local START = 0
local TARGET = 100
local TIME_TOTAL = 2 --in secs

local change = TARGET - START

local function outQuad(t, b, c, d)
  	t = t / d
  	return -c * t * (t - 2) + b
end

local startTime = tick()
local endTime = startTime + TIME_TOTAL

local value 

local function updateValue(i)
	value = outQuad(i, START, change, TIME_TOTAL)
   	print(value)
end

while tick() < endTime do
	local t = tick() - startTime
   	updateValue(t)
   	wait()
end

updateValue(TIME_TOTAL)

Sorry it took so long!

3 Likes

Just adding my 2 cents. (this could skip some numbers)

local goal = 100
local duration = 5
local start = tick()
local stop = start + duration
local t = start
local n = 0
while t < stop do
	n = math.floor(math.sin((t - start) * math.pi / 2 / duration) * goal)
	wait()
	t = tick()
end
n = goal
6 Likes

How did you figure THAT out???

Basically linear interpolation, but also applying math.sin to the interpolated value.

-- similar code without math.sin
local start = tick()
local stop = start + 5
local t = start
local n = 0
while t < stop do
	n = math.floor((t - start) * 100 / 5)
	wait()
	t = tick()
end

2 Likes