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

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

Asked by
popeeyy 493 Moderation Voter
5 years ago
Edited 5 years ago

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

Log in to vote
1
Answered by
Hexcede 52
5 years ago
Edited 5 years ago

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.
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? popeeyy 493 — 5y
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. Hexcede 52 — 5y
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. popeeyy 493 — 5y
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. Hexcede 52 — 5y
View all comments (5 more)
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 popeeyy 493 — 5y
0
Try my second edit... My guess is that the size is getting set at the same time as the starting variable. Hexcede 52 — 5y
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. Hexcede 52 — 5y
0
Edit 2 made it go backwards. popeeyy 493 — 5y
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. Hexcede 52 — 5y
Ad
Log in to vote
0
Answered by 5 years ago

idk what adjust is but lets say adjust is 5 and we want the bar change size

adjust = 5 
script.Parent.Size = Vector3.new(adjust,1,1)
script.Parent.CFrame = script.Parent.CFrame * CFrame.new(-adjust - 3,0,0) -- Negative or positive, test this on a basic part
0
That just made it fly off. https://gyazo.com/46c78ca95ffae2355e701c6aaf9a84c7 popeeyy 493 — 5y
0
test it on a 1,1,1 part DeathGunner132 120 — 5y
0
Still no. popeeyy 493 — 5y
Log in to vote
0
Answered by
spr_ead 47
5 years ago

Could do:

part.Position = anotherpart.Position+(part.Position/2)
0
That also made it fly into the middle of nowhere. popeeyy 493 — 5y

Answer this question