I have a screenGUI with multiple other TextLabels named 1-3, I also have a variable (chosenTextNumber) which chooses a random number between 1-3. Here is my code:

local chosenTextNumber = math.random(1,3)

for i,v in pairs(game.StarterGui.differentTexts:GetChildren()) do
	if v.Name == chosenTextNumber then
		print("HELLO THIS IS THE CORRECT THING")
		print(v.Name)
	end
end

5 comments

0

String type versus numeric type. Try v.Name == tonumber(chosenTextNumber).

0

That doesn't work.

0

I meant the other way around. v.Name == tostring(chosenTextNumber).

0

The point is that you need to either compare a string and a string or a number and a number. 1 isn't the same as "1".

0

Okay, that works. I didn't know how I would convert an integer to a string.