Problem with finding TextLabel.Text in a Table

Basically, the player has a list of numbers in the form of TextLabels, if one of those numbers is a number that was picked by a RNG, then a TextLabel text with that number turns to a different colour.

The list of numbers is stored in a table (textLabelContainer)

RNG ServerScript
local numMin = 1
local numMax = 25
local CD = game.ServerStorage.ServerEvents.CountDown
local GN = game.ServerStorage.ServerEvents.GotNumber

CD.Event:Connect(function()
	local currentNum = math.random(numMin,numMax)
	script.Parent.Text = currentNum --sets a different textlabel to the number picked, not important for this problem
	GN:Fire(currentNum) --fired a bindable event to another ServerScript with the number picked
end)
ServerScript that changes text colour

not the full script since most of it isnt important

ND.OnServerEvent:Connect(function(Player)
	local NumList = Player.Backpack.Tool.Handle.SurfaceGui.NumList --where all the TextLabels are ingame
	local textLabelContainer = {} --the table that has all the TextLabels

	for i,v in pairs(NumList:GetChildren()) do --this part is working
		if v.Name == "UIGridLayout" then continue else
			table.insert(textLabelContainer, v)
		end
	end 

	-- removed alot of code that would be here as it isnt important

	GN.Event:Connect(function(currentNum)
		for i = 1, 25 do --this part is also working
			if textLabelContainer[i].Text == currentNum then --this part is not working
				textLabelContainer.TextColor3 = Color3.fromRGB(249, 88, 88)
			end
		end
	end)
end)

what does the error in the output say?

1 Like

There is no error, forgot to include that in my post

I would recommend changing any UI with a local script, because it is held by the client

1 Like

Problem with that is that this is a SurfaceGui, so only the client would see that change

well, you technically could still do it client side, but I get your point

1 Like

You forgot to put [i] when setting the TextColor3

ND.OnServerEvent:Connect(function(Player)
	local NumList = Player.Backpack.Tool.Handle.SurfaceGui.NumList --where all the TextLabels are ingame
	local textLabelContainer = {} --the table that has all the TextLabels

	for i,v in pairs(NumList:GetChildren()) do --this part is working
		if v.Name == "UIGridLayout" then continue else
			table.insert(textLabelContainer, v)
		end
	end 

	-- removed alot of code that would be here as it isnt important

	GN.Event:Connect(function(currentNum)
		for i = 1, 25 do --this part is also working
			if textLabelContainer[i].Text == currentNum then --this part is not working
				textLabelContainer[i].TextColor3 = Color3.fromRGB(249, 88, 88)
			end
		end
	end)
end)
1 Like

the server events are not going to work, because server can’t invoke a server event, and a client can’t reach anything in the server storage

1 Like

its server to server using a bindable event

ooh… Then idk what the problem could be, maybe add some prints and check what’s running and what’s not?

1 Like

Wouldnt change anything, the script stops working at the part below

Already did that aswell, probably should of left them in for this post
The script works up asfar as

maybe try changing currentNum to tostring(currentNum) because youre trying to compare a string with a number

1 Like

ahhh, now i get it, you are comparing a string to a number so it doesn’t work

yeah what @CZXPEK said

2 Likes

thanks!! thought it was the way i was using the table since i dont understand them very well