#Continuously Scale a Model?
34 messages · Page 1 of 1 (latest)
First things first, you gotta figure out the initial size of your model. Get the original size by checking out its properties in Roblox Studio. Look for the properties like 'Size' or 'Scale' and note down the initial dimensions.
Next up, let's calculate the final size we wanna reach after 60 seconds. Multiply the initial size by 0.2 (20%) to get the desired final size.
Now, let's get coding! We're gonna need a loop to gradually scale down the model over time. The simplest way to do this is by using a 'for' loop that runs for 60 seconds (or 60 frames) with a slight delay between each iteration.
Inside the loop, we'll update the size of the model each frame. Divide the difference between the initial and final size by 60, and subtract that value from the model's current size each frame. This will gradually shrink it down until it hits the target size.
Here's some example code to give you a head start:
local model = -- [Insert your model here]
local initialSize = model.Size -- Or model.Scale, depending on what you're using
local finalSize = initialSize * 0.2
local duration = 60 -- In seconds
local frames = duration * 60 -- Convert seconds to frames
local delay = 1 / 60 -- Delay between each frame (1 divided by the frame rate)
for i = 1, frames do
local scaleFactor = (initialSize - finalSize) / frames
model.Size = model.Size - Vector3.new(scaleFactor, scaleFactor, scaleFactor) -- Or model.Scale, again, depending on your setup
wait(delay)
end
It should gradually shrink your model over 60 seconds until it reaches that sweet 20% of its original size. Remember to adjust the 'model' variable to match the actual model you're working with. Try it out, If it doesn't work let me know.
I tried calling model.Scale before, and model.Scale.Value, but the output says it isn’t a property
model.size is more like it, Are you using this to like just make it bigger or to extend the width and such?
also, using ??? is gonna give you a error obviously.
I’m trying to scale down the whole model over a period of time. I didn’t want to scale down each part individually because then there would be a large space between each part
Yeah I just put ??? because I wasn’t sure where to go from there.
¯_(ツ)_/¯
try the dev forum
https://devforum.roblox.com/t/how-to-scale-whole-model/1573481/2
My game uses this function, but I don’t know how it works because I stole it from someone on DevForum LOL If someone can explain what :lerp is without sending me the documentation website that I don’t understand that’d be appreciated <3 -- Don't forget to add a PrimaryPart!!!!! function resizeModel(model,a) local base = model.PrimaryPart.Pos...
yeah
always look for a solution there first you'll usually find something unless its like super obscure
Aw man, my bad guys.
I was on that page before but I didn't know there was a drop down.
All good man
local function scaleModelToPercent(model: Model, percentage: number, duration: number)
local ORIGINAL_SCALE = model:GetScale()
local TARGET_SCALE = ORIGINAL_SCALE * percentage
if duration == 0 then
model:ScaleTo(TARGET_SCALE)
return
end
local SCALE_RANGE = TARGET_SCALE - ORIGINAL_SCALE
local connection = nil
local secondsElapsed = 0
local alpha = 0
connection = RunService.Heartbeat:Connect(function(deltaTime: number)
if not connection.Connected then
return
end
secondsElapsed += deltaTime
alpha = math.min(1, secondsElapsed / duration)
model:ScaleTo(ORIGINAL_SCALE + SCALE_RANGE * alpha)
if alpha == 1 then
connection:Disconnect()
-- Clean up potential imprecision
model:ScaleTo(TARGET_SCALE)
end
end)
end
That's how I would do it
scaleModelToPercent(model, 0.20, 1)
Thanks so much! It's working, but I'm having a bit of trouble due to the lag it's causing. Would having it downsize every second (60 times total) reduce the lag?
** You are now Level 3! **
The code I wrote shouldn't cause lag
It's not your code, it's the application of it within the game I'm making.
How are you applying it?
I'm making a game where a cube rotates using roblox physics, and a person has to stay on top of the cube while it rotates.
Rounds are 60 seconds, and I was trying to add a round type where the cube continously gets smaller
That shouldn't cause lag
Some models are also made up of 500 separate parts
But I'm seeing a bit of roughness on 1 part models as well