Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Using variables inside an i, v in pairs loop does not seem to work?

Phase = 1
for i, v in pairs (script.Parent:GetChildren()) do
	if v.Name == Phase then
		v.Visible = true
	end
end

If I replace the "If name == phase then" to if name == "1" then" it works. It just won't work with variables. Anyone know why?

2 answers

✓ Accepted answer

You're trying to compare a string and a int value together. The reason why Name == "1" works is because of this. "1" is the string. You'll need to change the value of Phase to a string or use tostring() function to convert.

local Phase = "1" -- Either do this or use tostring()

for i, v in pairs (script.Parent:GetChildren()) do
	--The property .Name gives you a string
	if v.Name == Phase then
		v.Visible = true
	end
end


1 comment

0

Thanks!

The word Phase needs to be a string like this

if v.Name == "Phase" then --all ways put those quotation marks around 

the word a string

This discussion is preserved as it was. New answers, comments, and votes are closed.