Everything for making answer is in topic, but for clarification: i want to find command, which if property what i trying to find by this command doesn’t exist, it will return nil.
GetPropertiesOfClass is still in works by Roblox, so for now you can only pcall to make sure if the property exists
local Success, BackgroundColor3 = pcall(function()
return Part.BackgroundColor3
end)
if Success and BackgroundColor3 then
print("This Instance has this property")
end
For future: don’t use seperate pcalls for each property, rather just map trough desired property dictionary and check each one
There’s no direct equivalent of FindFirstChild() for properties, but you can do something like this:
local success, value = pcall(function()
return someInstance.SomeProperty
end)
if success then
print("Property exists:", value)
else
print("Property doesn’t exist")
end
Basically, pcall lets you safely check if the property exists without throwing an error. If it doesn’t exist, it’ll just return false instead of breaking your script.
Not as clean as FindFirstChild(), but it works!
You can check if the object belongs to the abstract class that creates the parameter.
For example, the BackgroundColor3 parameter is inherited from the GuiObject class
it will be a bit faster than pcall.
if not obj:IsA("GuiObject") then return end
This is just what FindFirstChild() is for and will do exactly that.
Also pcalls should be used for datastores or errors that beyond your control.
local part = workspace:FindFirstChild("SomePart")
if part then -- this will be nil and not go in here if so..
print("Found it!")
end
