Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How to check every value with GetChildren?

Asked by 9 years ago

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

Log in to vote
0
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

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
0
Ty ISellCows 2 — 9y
Ad

Answer this question