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

TweenSize exceeds the value I want it to be?

Asked by 3 years ago

So, I made a :TweenPosition() to occur whenever a person hovers their mouse to a textbutton, since I am doing this for multiple buttons I decided to use a for loop to loop through all of the buttons and give them that function; the consequences of this, is I wouldn't be independent to give the TweenPosition specific UDims for each button. So I decided to go with:

        button.MouseEnter:connect(function()
            for index, object in pairs(screen:findFirstChild("Objects"):GetChildren()) 
            do

                    button["button_label"]:TweenSize(
                        button["button_label"].Size + UDim2.new(0, 15, 0 , 0),
                        "Out",
                        "Quad",
                        .5,
                        true
                    )   
            end 
        end)

        button.MouseLeave:connect(function()
                    button["button_label"]:TweenSize(
                        button["button_label"].Size - UDim2.new(0, 15, 0 , 0),
                        "Out",
                        "Quad",
                        .5,
                        true
                    )
        end)
    end
end


When I do this, the tween returns me the Button's size as a random size chosen from 0 to 15, therefore when I continue with -UDim2.new(0, 15, 0, 0) It subtracts an unequal number and therefore exceeds below its original size. Can anyone give me an idea of what I could do here to match the given size and the number I'll subtract so it can return to its original size when I remove my mouse from it. **Thank you! I have more to improve! **

1 answer

Log in to vote
0
Answered by
Y_VRN 246 Moderation Voter
3 years ago
Edited 3 years ago

Try...

-- get the original TextBox position before both of the tween functions.

local origPos = button["button_label"].Position -- is this the correct ui object?

button.MouseEnter:Connect(function()
    for index, object in pairs(screen:FindFirstChild("Objects"):GetChildren()) do
        button["button_label"]:TweenSize(origPos + UDim2.new(0, 15, 0 , 0), "Out", "Quad", .5, true)  
    end
end)


button.MouseLeave:Connect(function()
button["button_label"]:TweenSize(origPos, "Out", "Quad", .5, true)
end)

on the MouseEnter and MouseLeave functions.

Also the uncapitalized versions of many functions are deprecated (such as connect() and findFirstChild(), like what you have used in your code.) Try not to use the old functions and go to the capitalized ones (like Connect() and FindFirstChild().)

Ad

Answer this question