How to check if an object's parent have changed?

i have been stuck on this for 2 days and i know for a fact that the answer is so stupid

heres my script and i want to check if the map’s parent have changed and then change the lighting to normal


	if game.Workspace["Amusement Park Map"].Parent == workspace then
		
		local atmos = game.Lighting.MapsAtmosphere 
		
		game.Lighting.TimeOfDay = 22
		
		atmos.Haze = 2.02
		
		atmos.Color = Color3.fromRGB(76,23,102)
		
		atmos.Density = 0
		
		atmos.Offset = 0
		
		atmos.Glare = 0
		
		atmos.Decay = Color3.fromRGB(104,104,104)
		
		
		
	elseif game.Workspace["Amusement Park Map"].Parent == game.ServerStorage.MAPS then
		
		
		print("Parent Changed")
		local atmos = game.Lighting.MapsAtmosphere 

		game.Lighting.TimeOfDay = 12

		atmos.Haze = 0

		atmos.Color = Color3.fromRGB(255,255,255)

		atmos.Density = 0

		atmos.Offset = 0

		atmos.Glare = 0

		atmos.Decay = Color3.fromRGB(255,255,255)
		
	end

You could do something like this:

Instance.AncestryChanged:Connect(function(_, NewParent)

end)

Your code won’t work. You check if the parent from the workspace is equal to the server storage
elseif game.Workspace["Amusement Park Map"].Parent == game.ServerStorage.MAPS then
game.Workspace["Amusement Park Map"].Parent - this is already in the workspace

And check for parent change:

part.AncestryChanged:Connect(function(child, parent)
	print(child.Name .. " is now a child of " .. parent.Name)
end)

Docs: Instance | Roblox Creator Documentation

it dosent seem to be printing anything, i have an another script that will assign the map to an another parent and when the parent have changed nothing prints in the output

btw the map is a folder that has all the assets into it i dont think it works with folders

Not an ideal method but if you only need to know if it’s in workspace or not.

if game.workspace[map] then
  --your code if in workspace 
else
  --your code if not in workspace
end

You would still need to connect this to an event obviously. Perhaps the one that reparents the map?