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

How to add a udim2 value to another udim2 value?

Asked by 5 years ago
Edited 5 years ago

Hello everyone, so I'm doing a thing with a GUI and I want to create a cool effect that moves a bunch of buttons inside a folder to the left each other, but the value always comes {0,0,0,0}

Here's the script:

for i,v in pairs (script.Parent.Parent:GetChildren()) do
            local Position = UDim2.new(v.Position + UDim2.new(-0.7,0,0,0))--I tried with - and * and didn't work
            v:TweenPosition(UDim2.new(Position),"Out","Quad",1)
            print(Position)--Prints {0,0},{0,0}
            print(v.Position) --+Prints high numbers such as  {0.0599999987, 0}, {0.649999976, 0} for some reason, shouldn't even be posible.
            wait(.3)
        end

Huge thanks to whoever helps me!

0
I might be wrong on this but I'm sure tweening happens asynchronously i.e. when you print v.Position the tweening has just started, so the output you're getting is close to where v is starting off at, not ending. realhomie86 20 — 5y
0
Even when I remove the tween line the same numbers appear. wilsonsilva007 373 — 5y
0
Yeah, that's v's original coordinates. 0.06,0.65 are reasonable scale coordinates, so nothing there is really out of place. Do you see the gui's position visually change when you tween it? realhomie86 20 — 5y
0
Yes. They all move to the "Position" value, which is {0,0},{0,0} wilsonsilva007 373 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

This is because the UDim2.new constructor expects 2 or 4 arguments, while you're just providing one, which will make it return "{0,0}, {0,0}".

To fix your script, you just have to remove the UDim2.new in the beginning, so it should look like this now:

for i,v in pairs (script.Parent.Parent:GetChildren()) do

        -- Fixing the position
        local Position = (v.Position + UDim2.new(-0.7,0,0,0))

        -- Tweening the button
        v:TweenPosition(Position, "Out", "Quad", 1);
        -- Waiting :o
        wait(.3)
end
0
Wow it was that simple? Thanks a bunch mate. wilsonsilva007 373 — 5y
Ad

Answer this question