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

Can someone help me with moving textlabels within an inventory?

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

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

2 comments

0

I am having trouble with removing it from the frame

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.

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