Event on Parent Change

Aight so I got a simple question (at least in my opinion); How do I fire an event whenever any model in a folder’s parent is changed? I know how to actually do the “Parent.Changed” stuff (I’m not that helplessly lost), what I need help on is finding the best way to apply this event to every model in a folder. I COULD duplicate a script 400 times but that seems extremely repetitive and like a really, bad practice.

(Explorer View)
image

Just a little more context; The “Models” are regions in a country, basically I want this script to fire every time a region is taken over and the region model is moved into a new country folder. Any help is appreciated, thanks for reading!

You can do this:

for _, object in ipairs(InstanceToHoldTheModels:GetChildren()) do
   -- this loops through each child in the folder
   -- 'object' is the Instance the loop is currently on
   -- '_' is the index that child has for the 'GetChildren' array (irrelavant here, hence why it's defined as '_')

   -- code here
end

use ancestry changed

something like the code above:

for _, object in pairs(InstanceToHoldTheModels:GetChildren()) do
	object.AncestryChanged:Connect(function(_, NewParent)

	end)
end
1 Like