Check for a property

HELP,
How do i check if a object has a property as i cannot find a way and i know i can do IsA() but i dont think that is good enough.
i am trying to invert all colors in workspace
ty bye

1 Like

Search before posting…

2 Likes

Why can’t you use IsA to check what the instance is?

use pcall

for i,v in pairs(workspace:GetDescendants()) do
	local HaveColor = pcall(function()
		local clr = v.Color
	end)
	if HaveColor then
		--Your script starts here
	end
end

Thanks for marking as Solution

9 Likes

A less hacky way of doing something like this would be to check the type of instances against a table with all the instance types that have the colour property.

1 Like

how do i get the child on this script

if child of Descendant then

v:GetChildren()[1] --First children

:GetChildren() returns table with childrens of something that have it
:GetDescendants() returns table with childrens and childrens of childrens and other childrens (Descendants)

1 Like

do you know how to invert colors as i need to now do that

i dont know how to invert Color3
but you can use Lighting way
i will write it soon

What does inverting the colours mean? Do you mean on a colour wheel?

ColorCorrectionEffect | Roblox Creator Documentation Try this

1 Like

There is that way to invert all colors

1 Like

yes i wanted to say about it

I need to invert the colors for them can you do that

i tried this and was not happy about the result

I found something about it on DevForum

function hasChildren(parent, ...)
	return pcall(function(...)
		for _, childName in pairs({...}) do
			_ = parent[childName]
		end
	end, ...)
end

function hasNested(parent,...)
	return pcall(function(...)
		for _, childName in pairs({...}) do
			parent = parent[childName]
		end
		return parent
	end, ...)
end

so you can do:

for _,child in ipairs(workspace:GetDescendants()) do 
   local good, result = hasNested(child,"Color")
   if good then child.Color = Color3.new(math.random(),math.random(),math.random()) end
end