Smooth number increase

I want to achive the smooth number increase like cookie clicker. For example if i have 100 cookies per second i want it to raise it to 100 in increments of one in only one second. If this is hard to understand just search upp cookie clicker and look for yourself. I have searched everywhere but i have not found anything that is what i am looking for. Please help.

You can use tweenservice.

1 Like

I believe you could use Tweens to do this.

Here’s the documentation on them.

1 Like

You can tween numbers. Example:

local NewValue = Instance.new("NumberValue")

local Tween = game:GetService("TweenService"):Create(NewValue, TweenInfo.new(1), {Value = 100})

NewValue.Changed:Connect(function()
 print(NewValue.Value)
end)

Tween:Play()

If you were to test this you would see the number go up smoothly in the output tab.

I still dont really understand. How would i tween my current value so that it increases by my cps. The cps is not a set value so it does change. And my cps value is a numbervalue inside of replicated storage. How would i do that?

Just change the NewValue variable to your cps variable

i tried that but it didnt work. Also what do i change the print to in the changed function?

Put the tween in a loop, this should update to your new CPS every second.

local Cookies = game:GetService("ReplicatedStorage").NumberValueHere
local CPS = 100

task.spawn(function() -- so that the script continues running
	while task.wait() do
		local Tween = game:GetService("TweenService"):Create(Cookies,TweenInfo.new(1), {Value = (CPS + Cookies)})
		Tween:Play()
		Tween.Completed:Wait()
	end
end)

the function is just there to show you that its going up smoothly

could you show me what you have tried?

I tried this but it said “Unable to cast value to Object” as an error. Heres the script:

task.spawn(function() – so that the script continues running
while task.wait() do
local Tween = game:GetService(“TweenService”):Create(chillis.Value,TweenInfo.new(1), {Value = (cps.Value + chillis.Value)})
Tween:Play()
Tween.Completed:Wait()
end

do you know how to fix the problem?

change chillis.Value to just chillis, the value part is handled in the 3rd parameter. You also forgot to add end)

It says “attempt to perform arithmetic (add) on number and Instance”

Just to clarify the cookie amount value is a leaderstats value (number value) and the cookies per second is a numbervalue inside replicated storage

try changing Value = (cps.Value + chillis.Value) to Value += cps.Value . If that doesn’t work, add an extra line:

local newcookies = tonumber(cps.Value + chillis.Value)

And change Value = (cps.Value + chillis.Value) to Value = newcookies

Thank you it works. But the number increases to what its supposed to go to but then stops for a tiny bit and then increases. For example lets say cookies per second is 5, then it goes to 5 then stops for like 0.01 sec and then goes to 10 and stops for 0.01 second. I think it has something to do with the “Tween.Completed:Wait()” but i tried removing that but then it just increased too fast.

Which of the provided methods worked?

the second one. (need to type this cause you need an amount characters to send mssg)

wait i changed the tweeninfo time to 2 seconds and it worked.