Tweening the size of model sometimes makes them HUGE

My game is a tycoon, and when you purchase something in the tycoon, an animation will play that resizes the bought model to be really small, and then quickly resizes it to what it is supposed to be.
This can be better visualized by viewing the below video:

However, a rare but notable bug will occur with this system, resulting in some absurd sizing cases like seen here in this video.

I am wondering what can be done to fix this issue. When an item is bought, it is originally in ServerStorage, before it is then moved to ReplicatedStorage for a frame, and then it is moved to the tycoon model in Workspace; this allows for the item to be loaded inside ReplicatedStorage so a client even can be fired to execute the animation in a local script, as seen below:

local GetScale = obj:GetScale();
		local sizeDiff = 10
		local i = 0.1;
		sound.tycoon.placing:Play()
		repeat
			i = math.min(i+task.wait()*2,1);
			obj:ScaleTo((i^2)*GetScale);
		until
		i == 1;

I used to use TweenService instead, but the issue I am describing would happen far more often using it.

How can I make this glitch even more rare, if not outright fix it?

1 Like

The math you are utilizing seems quite problematic. Roundoff errors and increased time elapsed could result in this issue. I would first recommend switching the i==1 to be i>=1. That would prevent round off issues that result in i being 1.00001. I would also adjust the +task.wait() portion to be a little more reliable. Maybe get the initial time in milliseconds with something like this:

DateTime.now().UnixTimestampMillis

You could then subtract that from the current time to get the elapsed time, and maybe divide by how long you want it to take(or just set that number randomly before the loop).

Lots of ways you could change this, but I believe switching that i==1 would be the biggest help(aside from the buggy nature of some roblox methods).

3 Likes

Thanks for the suggestion; I am going to try that out ASAP. Can’t believe I missed that simple solution!