One script that controls multiple parts problem!

So I’m trying to create an inventory with a scroling frame in there I have a lot of items and in all those items have a value wich shows the amount you have of that that item, it works fine I also have a text label wich needs to shows the value of how manny you have off that item, I could make in every single textlabel a script, but i tougth there must be a way to do it with one script but i don’t know how so can someone please help me with it? Heres the gui.

btw sorry for the ugly writing!

You’d want to use a for loop.

So you’d do something like this:

for _,item in itemsScrollingFrame:GetChildren() do
	local amount = item:FindFirstChild('AmountItem')
	if amount then
		item.AmountItemShower.Text = tonumber(amount.Value)
		amount = nil
	end
end

will this work for all my items? rigth?

Yes, I linked an article in my previous post of which explains it. A for loop will iterate through a table. Everything within the loop will happen to each item in the table.

local dictionary = {'a','b','c'}

for index,value in array do
	print(index,value)
end

Output:

1 a
2 b
3 c


local dictionary = {apple='red',banana='yellow',grape='purple'}

for key,value in dictionary do
	print(key,value)
end

Output:

apple red
banana yellow
grape purple

​Make sense?

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.