Detecting when a child has its properties changed

Hello, I just just wondering if there was a way to check if a child of an object has its properties changed. I want to refrain for putting a script in each child, help would be appreciated!
What I tried:

while true do wait()
	local hs = sticks:GetChildren()
	for a = 1, #hs do
			if arr[a] ~= hs[a].Value then
				print("check")
			local o = script.Parent.Background.InventoryContents:GetChildren()
			for l = 1, #o do
				if o[l].Name == hs[a].Name then
					o[l]:Destroy()
				end
			end
				for g = 1, hs[a].Value do
				if sticklibrary:FindFirstChild(hs[a].Name) then	
			local template = script.Template:Clone()
				template.Name = h[a].Name
				template.Image = sticklibrary[hs[a].Name].Decal.Value
				template.Parent = script.Parent.Background.InventoryContents
			end
			end
		end
		h = sticks:GetChildren()
		arr[hs[a].Name] = hs[a].Value
	end
	
end

It’s not necessary, but if I could also refrain from using a while true loop in my script, that would be great. Thank you!

1 Like

What do you mean?

Cant you use .Changed or GetPropertyChangedSignal?

These events are mainly used to check when a property changes.

To check when all properties change at once, I dont think you can, you might need to use an api for it. Or a simple loop( test it).

To rephrase what I mean,
When a child has its properties changed, it returns the child.
Sorry for the confusion.

I tried using putting a Changed function inside a loop going through all the children, it didn’t work that well.

Then I think you might want to use an api to detect when all the child properties have changed.

Here are some articles:

https://www.google.com/url?sa=t&source=web&rct=j&url=https://devforum.roblox.com/t/how-to-detect-changes-in-properties-of-parts-in-a-table/290451&ved=2ahUKEwif_f3MkrH4AhWPnqQKHbtUDfEQFnoECAQQAQ&usg=AOvVaw2A-DSJPEXnr8T1W5g86l9N

https://www.google.com/url?sa=t&source=web&rct=j&url=https://devforum.roblox.com/t/how-to-check-if-any-property-in-an-object-is-changed/1688315&ved=2ahUKEwif_f3MkrH4AhWPnqQKHbtUDfEQFnoECDEQAQ&usg=AOvVaw0IN0667BwKo4ogzSgb9Gy5

https://www.google.com/url?sa=t&source=web&rct=j&url=https://devforum.roblox.com/t/how-to-detect-changes-in-properties-of-parts-in-a-table/290451&ved=2ahUKEwiOo5fkkrH4AhUowQIHHQVKCoMQFnoECB0QAQ&usg=AOvVaw2A-DSJPEXnr8T1W5g86l9N

Thank you for your time, no clue how to make an API.

You should elaborate some more.
Do you mean you wanna use .AncestryChanged ?

.AncestryChanged only detects if a child has its parent changed. I am referring to detecting when a (a child: number value)'s value gets changed, returns the child

Is this what you mean?

local object = whateverHere
local ChildsPropertyChanged = {}

object.ChildAdded:Connect(function(child)
    child.Changed:Connect(function()
        table.insert(ChildsPropertyChanged, child)
    end)
end)

for _,child in next, object:GetChildren() do
    child.Changed:Connect(function()
        if not table.find(ChildsPropertyChanged, child) then
            table.insert(ChildsPropertyChanged, child)
        end
    end)
end
2 Likes
local Cache = {}

local function OnChanged(Value, Child)
	print(Child.Name.."'s value changed from "..Cache[Child].." to "..Value..".")
	Cache[Child] = Value
end

for _, Child in ipairs(Parent:GetChildren()) do
	if not (Child:IsA("ValueBase")) then continue end
	Cache[Child] = Child.Value
	Child.Changed:Connect(function(Value)
		OnChanged(Value, Child)
	end)
end
1 Like

Thank you! It works just like I wanted it too.