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

How to check every value with GetChildren?

I was wondering how if I can make this script check every value, if it the value of each BoolValue is true then to return false. But I'm not exactly sure how to. Can anyone help?

gather = workspace.Model1:GetChildren()
for i = 1,#gather do
if gather[i].Value == true then return false
end
end

1 answer

✓ Accepted answer

You have the right cocept, just you're using the return statement inproperly.

The return statement is a statment that should be used in a function. It makes whatever function you used the statement on return the given argument, and also discontinues the function. Example;

function add(a,b)
	return a + b
	print('lol') --This won't print
end

print(add(1,3)) --> 4

But that's besides the point. Instead of returning false, set the value to false.

local gather = workspace.Model1:GetChildren()

for i = 1,#gather do
	if gather[i].Value == true then
		gather[i].Value = false
	end
end

Additional changes - you can use a generic for with the Pairs function.. which is actually meant to iterate through tables.. also you can 'toggle' the value by doing value = not value.

local gather = workspace.Model1:GetChildren()

for i,v in pairs(gather) do
	v.Value = not v.Value
end

--And if you don't want to toggle it then just return it to the old syntax(:

for i,v in pairs(gather) do
	if v.Value then
		v.Value = false
	end
end

1 comment

0

Ty

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