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

How do I make a i,v loop not error on things that dont have things?

Asked by 4 years ago

Some things in workspace dont have a value and when im looping through it errors is there any way to fix this?


for i,v in pairs(game.Workspace:GetChildren()) do local Value = v.Value -- Some things in workspace dont have a value and it gets stuck there and errors print(Value.Value) end

1 answer

Log in to vote
0
Answered by
lolzmac 207 Moderation Voter
4 years ago
Edited 4 years ago

You can use :IsA to whitelist the classes you want, including values.

You can add this to your script to only include Values you want, for example:

for i,v in pairs(game.Workspace:GetChildren()) do
    if v:IsA("ObjectValue") or v:IsA("BoolValue") then
        local Value = v.Value 
        print(Value)
    end
end

Prints only the values of ObjectValue and BoolValue. Also, if you don't want these values to print nil if they're nil, you can add an extra if v.Value ~= nil under the first if.

0
Yes lolzmac Eternalove_fan32 188 — 4y
Ad

Answer this question