Loop through all children and change boolvalue

i have these TextLabels in a frame and i wanna loop through all the TextLabel’s text and turn TextScaled on only for the ones that do not have the text “[No Player]”
image

What, nobody answer because we don’t understand ?

im wondering how to make a script that will loop through all the children of the frame named “People” in the picture, and change TextScaled to true for the all the childrens whose text is not “[No Player]”
image

Here is an example of how you can do it:

local Frame = script.Parent -- let's say your script is parented to your main frame

for i, v in pairs(Frame:GetChildren()) do -- loops through all the instances under 'Frame'
	if v:IsA("TextLabel") then -- checks if any of the children is a 'TextLabel'
		if v.Text ~= "[No Player]" then -- checks if the text of any TextLabel is not "[No Player]"
			v.TextScaled = true -- sets 'TextScaled' to true
		end
	end
end
2 Likes
local Frame= -- path to your frame
for _,v in ipairs(Frame:GetChildren()) do
	if v:IsA("TextLabel") and v.Text~="[No Player]" then v.TextScaled=true end
end

I see you mean do that ?

local Frame = script.Parent

for _,v in ipairs(Frame:GetChildren()) do
	if v.ClassName == "TextLabel" and v.Name == "People" then
         if v.Text ~= '[No Player]' then
            v.TextScaled = true
        end
    end
end

after using this script, but changing the location of the frame. no errors occur but none of the TextScaled’s are changed, i added a print(“test”) after
for i, v in pairs(Frame:GetChildren()) do
but it didnt print anything at all.
is this possible with a while true do loop?

Could you please show your current code? Also, are you using a LocalScript or a Server Script, because you should be using a LocalScript for this.

here is the script, and yes i am using a localscript

local Frame = script.Parent.Cell.People
for i, v in pairs(Frame:GetChildren()) do -- loops through all the instances under 'Frame'
	print("test")
	if v:IsA("TextLabel") then -- checks if any of the children is a 'TextLabel'
		if v.Text ~= "[No Player]" then -- checks if the text of any TextLabel is not "[No Player]"
			v.TextScaled = true -- sets 'TextScaled' to true
		end
	end
end

image

The script should be a direct child of the ‘Cell’ ScreenGui. Try putting the script under the ScreenGui. Or insert another LocalScript, parent it to the ScreenGui, and paste the code in that script

same result after moving script into Cell, all i did was change
local Frame = script.Parent.Cell.People
to
Local Frame = script.Parent
image

I think you meant to do local Frame = script.Parent:WaitForChild(“People”). Does the print function print anything in the output?

thanks for pointing that out, but after changing it there is still no changes

and the print function is not printing anything in the output

Does the TextLabels Text change from time to time from another script? Because if so, you should be calling the GetPropertyChangedSignal event for that.

one of the textlabel’s will change when a player joins to display their username
how would i incorporate that into the script? sorry for my lack of script knowledge

local Frame = script.Parent:WaitForChild("People")
for i, v in pairs(Frame:GetChildren()) do -- loops through all the instances under 'Frame'
	print("test")
	if v:IsA("TextLabel") then -- checks if any of the children is a 'TextLabel'
		if v.Text ~= "[No Player]" then -- checks if the text of any TextLabel is not "[No Player]"
			v.TextScaled = true -- sets 'TextScaled' to true
		end
	end
end

Try this:

local Frame = script.Parent:WaitForChild("People")

for i, v in pairs(Frame:GetChildren()) do -- loops through all the instances under 'Frame'
	print("test")
	if v:IsA("TextLabel") then -- checks if any of the children is a 'TextLabel'
		if v.Text ~= "[No Player]" then -- checks if the text of any TextLabel is not "[No Player]"
			v.TextScaled = true -- sets 'TextScaled' to true
		end
		
		v:GetPropertyChangedSignal("Text"):Connect(function() -- if any of the TextLabels 'Text' changes
			if v.Text ~= "[No Player]" then
				v.TextScaled = true
			end
		end)
	end
end
1 Like

that fixed it!!
thank you so much

1 Like

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