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

How do I change the size of a part in just 1 direction?

Asked by 8 years ago

I'm trying to make it so that, when you change the size of a part with code, the part will only scale in the direction I want it so. This is similar to how the scale tool will only increase the size of a part in the direction that you drag it.

So far, this is the only code I have

local part = workspace.part1

while true do
    part.Size = part.Size + Vector3.new(0,1,0)
end

2 answers

Log in to vote
0
Answered by 8 years ago

There's a trick that you can do to mimic the effect of a part's size changing in one direction. You can do the inverse of what you're doing on the size of the part onto the position of the part and it'll look like the part is being re-sized in one direction.

For example: If you're adding 1 on the part's Y size, subtract 1 from the part's Y position to gain the effect.

Also, you must have a wait() in your loop, otherwise ROBLOX will crash because the loop is running too many times. A simple trick to do this is while wait() do.

Your code should look something like this:

local part = workspace.part1

while wait() do --Using wait() instead of true as you need a wait() in any loop, otherwise ROBLOX will crash.
    part.Size = part.Size + Vector3.new(0,1,0)
    part.Position = part.Position - Vector3.new(0,1,0)
end

I hope my answer helped you. If it did, be sure to accept it.

0
What if the part has been rotated by (0,-45,0)? How would I make it do this then? Ross1397 25 — 8y
0
Does it not work when you rotate the part? Spongocardo 1991 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Haven't had much time to work on it, but this should work. Message me if you have any issues with this. I'm assuming the part is (1,1,1)

local part = workspace.part1

while wait() do
    part.Position = Vector3.new(0,0,0)
    part.Rotation = Vector3.new(0,0,0)
    local pos = part.CFrame
    part.Size = part.Size + Vector3.new(1,2,1)
    part.CFrame = pos*CFrame.new(0,0.5,0)
end

Answer this question