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

How can i get a part to resize smoothly?

Asked by
Sketchi 18
5 years ago

I have a script that sizes a part to grow bigger then back smaller on click. But I had to manually add the size into a script to change, it's very choppy and it takes too much time. Is there a different way I can do this? Also, my welds keep breaking so I'm using motor6d, is this fine too?

Thank you

0
You can use TweenService DevingDev 346 — 5y
0
Let's talk here so you can get alerted too. superalp1111 662 — 5y
0
I didn't understand what you mean actually, can you be more specific about it? If I am thinking right, you may not be anchored it. Anchor it if you didn't already. If it's something you shouldn't anchor(TweenService works best with anchored parts though,) you need to be more specific. Why you shouldn't anchor it? Why does weld breaks it? Etc. superalp1111 662 — 5y
0
You can also contact me via Discord for faster communication. @HalilAlper#0255 superalp1111 662 — 5y
0
Im sorry i havent been on i wanted to come back to it because it was stressing me, i was setting the cframe to the anchor point instead of position, it works flawlessly my only issue is the tween lags on servers when cloned by a player, i cant find a fix for it so i might just forget about the part growing and shrinking thanks for replying and again, i apologize for the very late reply Sketchi 18 — 5y

2 answers

Log in to vote
2
Answered by 5 years ago

TweenService - A great way to do things smoothly, change things smoothly. If you want to read more, Click Here!

Now I'll of course show you a few lines you can use but if it becomes helpful to you, please upvote! (I need that so bad...)

To tween, first of all you will need TweenService. A line of GetService command will be enough.

local TweenService = game:GetService("TweenService")

Then let's get our part that we want to resize.

local Resize = game.Workspace.ResizeMe

Let's say we want to change it's size to 1,1,1, for that we first assign an empty table and equal it's "Size" property to 1,1,1

local Goal = {}
Goal.Size = Vector3.new(1,1,1)

--I want to change color as extra
Goal.Color = Color3.new(0,1,0) --Green

Now we create a TweenInfo. It goes as: Time, EasingStyle, EasingDirection, a few more parameters that you better check yourself. For now, I'll just assign the time.

local TwInfo = TweenInfo.new(2)

Now we create the tween with these parameters: Object, TweenInfo and Goal. Then we play it.

local Tween = TweenService:Create(Resize, TwInfo, Goal)
Tween:Play()

For more functions of TweenService, check the page. Click Here!

0
Thank you, yours worked the best. But the only issue im having now is....i made it loop with a while true do, so when it clicked again it stops growing and shrinking, but it moves ever so slightly off center of the platform its placed on. I tried a weld, it breaks, i tried a motor6, it flings it across the map, and i tried a weld constraint and it still moves. How can i fix that? Sketchi 18 — 5y
Ad
Log in to vote
1
Answered by 5 years ago

http://wiki.roblox.com/index.php?title=API:Class/TweenService

I made a quick demo here:

local TS = game:GetService("TweenService")
local part = script.Parent
local small = true
local goal = {}

part.ClickDetector.MouseClick:Connect(function()
    if small == true then
        small = false
        goal.Size = Vector3.new(4, 4, 4) --Size part should be when it's BIG
        local tweenInfo = TweenInfo.new(2) --Time in seconds from start to end of animation

        local tween = TS:Create(part, tweenInfo, goal)
        tween:Play()
    else
        small = true
        goal.Size = Vector3.new(4, 1, 2) --Size part should be when it's SMALL
        local tweenInfo = TweenInfo.new(2) --Time in seconds from start to end of animation

        local tween = TS:Create(part, tweenInfo, goal)
        tween:Play()
    end
end)

Answer this question