Change part size while keeping it at the same position

  1. What do i want to achieve?
    I want to keep part attached to floor, here is expample:
    Снимок экрана 2023-08-11 в 23.09.00
    I want to change size to this:
    Снимок экрана 2023-08-11 в 23.10.18
    but then im trying to change size it happends to be like this:
    Снимок экрана 2023-08-11 в 23.15.50
    problem is simple as that! plz help :smile:
4 Likes

this happened to me once i think you have to tween it and in the tween property array
write this:
local tween = tweenservice:Create(part,tweeninfo,{Position = yourpos, size = yoursize})
tween:play

this will resize it and also adjust it’s position with it’s new size

so the full script is:

local Tweenservice = game:GetService("TweenService")
local Tweeninfo = TweenInfo.new(YourPrefferenceshere)
local Part = yourpart

local Tween = Tweenservice:Create(Part,Tweeninfo,{Position = TheCurrentPosition,Size = NewSizeYouWanted})
Tween:Play()

but you can’t use Part.Position for currentposition it would have to be a vector3 with the position

I dont understand what do you mean, My part position isnt changing, but i want to change like so bottom part will stay on the same place

Maybe this topic can help you a bit on your situation?

1 Like

okay let me explain, you want to change your size right?
well positions in rblx studio are centered, meaning that the position property is pointing towards the center of the object!
so when you resize it , the center will obviously change, and it will get stuck in the floor.
to avoid this, you add a position property so that rblx knows to resize it and keep it on the correct position! the position itself (if correct) won’t give any visual difference but the size will, and the part will stay in place

1 Like

Maybe im stupid, but i dont understand, leme give you analogy, like bee swarm simulator pollen, then you dig it it goes down until it is gone, same with me, i need same system where i will change size of object then position

As others have mentioned, the part has to be simultanously moved in the opposite direction.

The part’s final position has to be half of the size change downwards in your case. To supplement the related topic sent above, you can use CFrame instead of position for this to apply to rotated parts as well, and not only on the world axis. Additionally, to properly find the final position, we have to know the exact difference between the old and the new size, not only the new size.

We are interested in the difference between the initial size and the new size, divided by two.

initialSizeY = 10
newSizeY = 5
difference = abs(10 - 5) = 5
positionChange = 5/2 = 2.5

Here’s a stand-alone example. It keeps the position of the part on Y-axis regardless of orientation in the world.

local TweenService = game:GetService("TweenService")

local part = Instance.new("Part")
part.Size = Vector3.new(2,15,2)
part.CFrame = CFrame.new(0,7.5,0) -- * CFrame.Angles(0,0,math.rad(45)) -- optional rotation
part.Anchored = true
part.Parent = workspace

local newSize = Vector3.new(2,5,2)

local tween = TweenService:Create(part, TweenInfo.new(5), {
	Size = newSize,
	CFrame = part.CFrame * CFrame.new(0, (newSize.Y - part.Size.Y)/2, 0)
})
tween:Play()

Adding a minus in front of (newSize.Y - part.Size.Y)/2 would work in the opposite direction.

This logic applies to both other axes.

2 Likes

I think it should work but for whatever reason even then its on -3 it stays like that
Снимок экрана 2023-08-11 в 23.52.35

local function updateBlock(percent,block,fullBar)
	local size = Vector3.new(fullBar.Size.X, fullBar.Size.Y*percent, fullBar.Size.Z)
	local pos = fullBar.CFrame*CFrame.new(0,(size.Y-block.Size.Y)/2,0)
	
	block.Size = size
	block.CFrame = pos
end

	updateBlock((block.BlockConfig.Health.Value*100/block.BlockConfig.MaxHealth.Value)/100,block,block.FullBar)

EDIT. Never mind, fixing something…

EDIT 2. @bletDemonJH

image

Has to apply to the existing block.

block.CFrame * CFrame.new(...)

I assume fullBar is a template of an object value pointing to the template.

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.