Hello
Can I create a Tween, which changes a given number between 1 and 100, by generating only the whole numbers - 1, 2, 3, 4, etc. ?
Or can I create a Tween, which lasts 20 seconds but changes the value of the controlled attribute only 10 times ?
I do not want to generate random numbers.
I am specifically interested in the Tween service.
for example I would like to generate the numbers between 1 and 10 for a total of 10 seconds.
I know that I can do it with a for loop and wait(), however I am not sure how accurate and how efficient this will be compared to Tweening.
You mean you want to smoothly change an intvalue from 1 to 10? Oh then here’s the code:
local TweenService = game:GetService"TweenService"
local intvalue = workspace.IntValue -- let's assume it is set to 1 before the code runs
local tweenInfo = TweenInfo.new(
2, -- Time
Enum.EasingStyle.Linear, -- EasingStyle
Enum.EasingDirection.Out, -- EasingDirection
0, -- RepeatCount (when less than zero the tween will loop indefinitely)
false, -- Reverses (tween will reverse once reaching it's goal)
0 -- DelayTime
)
local goal = {
intvalue.Value = 10
}
local tween = TweenService:Create(part, tweenInfo, goal)
tween:Play()
No, this will generate multiple intermediate values like 1.3, 1.55, 1.76, 2.12, etc.
I need the tween to generate the 10 whole numbers - 1, 2, 3, 4, 5, etc.
When saying “generate numbers”, I mean the value of the “tweened” attribute on each iteration - in your case “intvalue”.
Your tween will change the intvalue from 1 to 10, but if you print the changed values on each iteration they will not be 1, 2, 3, 4, 5 ,etc.
Maybe the thing you’re trying to achieve can be done another way? Tween can only get a value and change it according to the tweeninfo and goals. Can you describe what will you use this for?
I will subscribe function to the “changed” event of the “intvalue” and will use the “generated” whole number in my script.
I know how to do it with loop and wait().
I am basically interested in the question in the title of the topic - if I can do this with a “tween”…
Because on the tween I can put the exact timing for the whole loop (10 sec.) and I expect it to be a better practice compared to loop and wait().
But I do not find information whether “I can control the number or timing of the discrete steps in a Tween”, so I guess it is not possible…
Yes, you can create a Tween which changes a given number between 1 and 100 by generating only the whole numbers - 1, 2, 3, 4, etc. To do this, you would need to set the Tween’s “Mode” property to “One Way” and its “Ease” property to “Linear”.
I hope I’m not too late to this, but I had a similar problem and used
math.round(Example)
Just set it on a while loop so it stays accurate.
Make sure you also have it rounded on a different value that’s equal to the original, so it still goes at the rate you want.