Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When I size a part, how do I change it's position to stay on another part?

I have this code:

part.Parent.Parent.StatusBar.Status.Size = Vector3.new(adjust, 0.45, 0.07)

And when I change the size of the status bar, it looks like the one on the left in this picture. https://gyazo.com/98227cac311248ffb70e1dc104ccb8a8 How do I determine the position so it looks like the one on the right and is always scaled on the part while it's moving? It may look like this when it's moving: https://gyazo.com/a98ad47562fbf1be048de087e271445b

EDIT: Whole Code

					local length = 15
					local current = 0
					local barlength = 5.75
					local adjust = current/length * barlength
					local lastX = part.Parent.Parent.StatusBar.Status.Size.X
					local originalSize = part.Parent.Parent.StatusBar.Status.Size.X
					local function reAdjust()
						adjust = current/length * barlength
					end
					local function size()
						--part.Parent.Parent.StatusBar.Status.Size = Vector3.new(adjust, 0.45, 0.07)
						tweenSite(part.Parent.Parent.StatusBar.Status, Vector3.new(adjust, 0.45, 0.07))
						--part.Parent.Parent.StatusBar.Status.CFrame = part.Parent.Parent.StatusBar.Status.CFrame * CFrame.new(-adjust - 3,0,0) 
						part.Parent.Parent.StatusBar.Status.CFrame = part.Parent.Parent.StatusBar.Status.CFrame*CFrame.new(adjust/2-originalSize/2, 0, 0)
						--part1.Position = otherPart.Position+(part1.Position/2)
						--local differ = part.Parent.Parent.StatusBar.Status.Size.X - lastX
						--differ = differ / 4
						--part.Parent.Parent.StatusBar.Status.Position = part.Parent.Parent.StatusBar.Status.Position - Vector3.new(differ, 0, 0)
					end
					repeat
						wait(.5)
						if current <= length then
							print(current)
							current = current + .5
							reAdjust()
							size()
						end
					until current == length

3 answers

✓ Accepted answer

I know I am a little late to answer but this is probably what you are looking for...

local originalSize = part.Parent.Parent.StatusBar.Status.Size.X
part.Parent.Parent.StatusBar.Status.Size = Vector3.new(adjust, 0.45, 0.07) -- Set the size of the part
part.Parent.Parent.StatusBar.Status.CFrame = part.Parent.Parent.StatusBar.Status.CFrame*CFrame.new(adjust/2-originalSize/2, 0, 0) -- Offset the bar by half of the size  to move it from it's center to the side.

Edit: Example of what I mean in my comment:

local originalSize = part.Parent.Parent.StatusBar.Status.Size.X
part.Parent.Parent.StatusBar.Status.Size = Vector3.new(adjust, 0.45, 0.07) -- Set the size of the part
part.Parent.Parent.StatusBar.Status.CFrame = part.Parent.Parent.StatusBar.Status.CFrame*CFrame.new(-(adjust/2-originalSize/2), 0, 0) -- Offset the bar by half of the size  to move it from it's center to the side.

Basically what it does is offset the bar from the center so that it stays in the same location as it started from. You can adjust the CFrame.new values which will change the relative offset to it's position and rotation. Z is backward so negative z is going in the direction the front face is facing, y is up and down so positive y is up and negative y is down, and x is left and right (I don't remember which is negative/positive but you can do some testing if you want to know).

Edit 2: Try this because it seems like it's because of the order of the properties being set and the variables being used:

part.Parent.Parent.StatusBar.Status.CFrame*CFrame.new(part.Parent.Parent.StatusBar.Status.Size.X/2, 0, 0) -- Offset the bar at the start to try and avoid bouncyness
part.Parent.Parent.StatusBar.Status.Size = Vector3.new(adjust, 0.45, 0.07) -- Set the size of the part
part.Parent.Parent.StatusBar.Status.CFrame = part.Parent.Parent.StatusBar.Status.CFrame*CFrame.new(-adjust/2, 0, 0) -- Offset the bar by half of the size  to move it from it's center to the side.

9 comments

0

That made it go all the way to the other end. https://gyazo.com/4b6d06319857fdfe590016e20223c856 How could I make it STAY on the bar?

0

Do you mean the bar is going in the wrong direction? If that's what you can you can put the first argument of CFrame.new inside of some parentheses and make the whole thing negative so it offsets in the opposite direction.

0

No, the bar is going off of the little bar it's supposed to stay on. Look at the first little grey bar and look at the rest of the bars. In the end, that green is supposed to look like the other green parts.

0

Also if the bar is zooming away try resetting the position of the bar before you call the adjust code if you aren't doing it already. Otherwise let me know.

0

Ok, it works now. But, it doesn't look smooth and it's bouncy. How would I fix that? I made the position start to reset. https://gyazo.com/c9489c592cdd1ca24ec0704faba0959b

0

Try my second edit... My guess is that the size is getting set at the same time as the starting variable.

0

Oh I didn't see your full code yet but it wouldn't hurt to try that edit... It could be some weird Roblox physics thing too... I've had that issue once.

0

Edit 2 made it go backwards.

0

Then try making both of the cframe offsets negative like I said before... It's either the adjust one or them both so if it's slightly offset from it's starting position try making both negative instead of the one that uses adjust.

Could do:

part.Position = anotherpart.Position+(part.Position/2)

1 comment

0

That also made it fly into the middle of nowhere.

This discussion is preserved as it was. New answers, comments, and votes are closed.