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

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

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

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.

1 comment

0

Yes lolzmac

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