Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Am I able to tween a number value in a script?

Asked by
yellp1 193
5 years ago

I am wondering if you can use tweenservice to tween a number in a script

local number = 1

game:GetService:("TweenService"):Create(number, TweenInfo.new(1), {0})

1 answer

Log in to vote
1
Answered by
jaschutte 324 Moderation Voter
5 years ago

This should do it:

local tweenedNumber = 0
function tweenNumber(current, goal, totalSteps, runFunction)
    for i = 1,totalSteps,goal/totalSteps do
        tweenedNumber = i
        if runFunction then
            runFunction(i)
        end
    end
end

--to get the tween, use tweenNumber.
--example:
tweenNumber(0,30,30, function(x) print(x) end)
--prints out 1,2,3,4,5..30
Ad

Answer this question