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

Can someone help me with moving textlabels within an inventory?

Asked by
sad_eyez 162
7 years ago

I am trying to make text labels move down when they get added and move up when they are sold but without making the on at the top go to far, here are my codes i tried doing:

When adding to inventory:

for i,j in pairs(inv:GetChildren()) do
            if j.ClassName == "TextLabel" then
                j.Position = UDim2.new(0, 0,0, (50 * #inv:GetChildren()))
            end
        end

When being sold and deleted from inventory:

for i,v in pairs(inv:GetChildren()) do
        if v.ClassName == "TextLabel" then
        v.Position = UDim2.new(0, 0,0, (50 * #inv:GetChildren()))
        end
    end

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
7 years ago
Edited 7 years ago

I suggest just repositioning them each time. I've had problems where removing or adding them will cause problems (spaces) if both happen at the same time. Also, if you wanted to animate (tween) them, it works better when there's a set position.

local y = 50

local function repos()
    local pos = 0
    for i,v in pairs(inv:GetChildren()) do 
        -- Retain Scale and Offset on the X axis if there was any when you first created them.
        v.Position = UDim2.new(v.Position.X.Scale,v.Position.X.Offset,0,pos)
        pos = pos + y -- + padding (y-spacing) if there is any.
    end
end
0
I am having trouble with removing it from the frame sad_eyez 162 — 7y
0
An easy way is to insert the TextLabel and name it the same as everything else that corresponds to your item. You can then remove it based on the name. A better, but more complicated way is to use a nested array that contains all of the information you need to refer back to that label. Azarth 3141 — 7y
Ad

Answer this question