Value showers problem!

So I’m trying to make a value show on a text label i know how to do it but i have like a 100 textlabels so does anyone know how i can make every textlabel display the amount of a value they all have a difrent one and with one script is there a way for that?

1 Like

If you want to change a large number of textlabels at once, you can do something like this:

local TextLabels = script.Parent.Labels -- Have all of the textlabels have the same parent
for index, Label in ipairs(TextLabels:GetChildren()) do
    if not Label:IsA("TextLabel") then continue end -- Just in case it isn't a textlabel
    Label.Text = "VALUEGOESHERE"
end
1 Like

The value is in the text labels is there a way to get them then to like get the children of all the text labels

1 Like

You can use :GetDescendants() to get the children of children.

print(script.Parent:GetDescendants())
image
image

and then with that table you could use an ‘if’ statement to determine whether or not it does contain a value, if it does then set it as the text, etc.

Also, if the value is able to change during gameplay I recommend using this inside of a for loop

--this is inside your for loop
ValueName.Changed:Connect(function()
    --change text to value
end)

so whenever the value changes it will run this portion of code again

1 Like

thats execlty what I’m trying to do but i have no idea how this is my script rigth now

local Items = script.Parent

for index, label in pairs(Items:GetChildren()) do
	if label:IsA("TextLabel") then
		for i, v in pairs(label:GetChildren()) do
			if v:IsA("NumberValue") then
				if v.Value >= 1 then
					v.Parent.Visible = true
					v.Parent.AmountItemShower.Text = v.Value.."x"
				end
				v:GetPropertyChangedSignal("Value"):Connect(function()
					if v.Value >= 1 then
						v.Parent.AmountItemShower.Text = v.Value.."x"
					else
						v.Parent.Visible = false
					end
				end)
			end
		end
	end
end

but it doesnt work and there are no errors, can you please help me out?

2 Likes

Ok firstly here I’m pretty sure you want it to be Visible again right?

				v:GetPropertyChangedSignal("Value"):Connect(function()
					if v.Value >= 1 then
						--
						-- here should be Visible = true right?
						--
						v.Parent.AmountItemShower.Text = v.Value.."x"
					else
						v.Parent.Visible = false
					end

Also, please show where & what AmountItemShower is because when I remove that and just use V.Parent.Text (as you said the values are inside the text labels) it works fine

1 Like

But i don’t get the part getting the child of the child thats whats going wrong and using the v and IsA i have no idea what I’m even doing

Okay, so :GetChildren() will get any ‘Child’, which must be an instance (part, gui, value, etc all instances) that has been placed inside of another instance - the ‘parent’.
So, using :GetChildren() on this Part:
image
will give me SurfaceGui, but not Script, TextLabel, or Value, because it’s not a Child of the Part, it’s a Child of SurfaceGui as it is listed underneath it.

And :GetDescendants() (which isn’t necessary here but I’ll explain anyway) does what :GetChildren() does, except it continues going through every instance, and every instance’s child, until there is no more Children.
image
So using it on Part here would give me SurfaceGui, Script, TextLabel, and Value as they are all inside an instance which is a Child of the part.

For loops are used on arrays primarily to run through the array elements (element = data stored inside the array), and carry out an instruction on those elements. Each element has an ‘index’ - a numerical position value for where the element is in the array.
image
(This is from one of my previous comments) Those [#] numbers are the index, based on when the for loop found the instances, TextLabel3 would be [1] and Value as [2] because they were detected one after another.

In most for loops, ‘i’ is used rather than ‘index’ just to speed up programming, as well as ‘v’ rather than ‘value’. Here on the Roblox development docs they explain pairs better than I was going to lol.

So this:

abcd = {
	"a",
	"b",
	"c"
}
for i, v in abcd do
	print(i, v)
end

will print:
image

If something I said didn’t make sense check out the create.roblox.com Documentation which explains literally everything.

1 Like

I really apriciate it thanks__

1 Like