Answered by
5 years ago Edited 5 years ago
You could use pcall()
, which catches errors and prevents them from breaking your script. Calling a function with pcall()
will return two or more values: the first one is a bool (true or false) which indicates if the called function ran without error, and the rest are any values returned by the called function.
Below, hasSizeProperty
will be true
if the inner function doesn't throw an error.
Furthermore, size
will be set to v.Size
.
01 | for i, v in pairs (game.StarterGui.ScreenGui:GetDescendants()) do |
02 | local hasSizeProperty, size = pcall ( function () |
03 | return (v.Size ~ = v:FindFirstChild( "Size" )) and v.Size |
05 | if hasSizeProperty then |
06 | print (v.Name .. " has size " .. tostring (size)) |