Child.Added Check Previous Parent

Hey, I just had a simple question I was hoping someone could answer. I’m just checking to see if there’s a way I’d be able to see what an Object’s previous parent was.

Inventory.ChildAdded:Connect(function(Object)
	
	-- Get object's previous parent?
	
end)

Store the object’s previous parent before its parent is changed, inside a variable. For example:

local parent = Object.Parent

Before the ChildAdded event is fired.

Well that’s the thing, I don’t know what the object is.

Edit: Basically this “Object” is a tool, and it gets moved from the players backpack to the player’s model. But I also have a custom toolbar that used Child.Added & Child.Removed. The issue is that since the tool changes parents when it is equipped, it continues to create Guis. So I’m trying to determine if the Tool had been a child of the Player’s model or if it was just barely given to the player.

image

So essentially I just need to know if the tool was just given to the player, or if it was previously in the player’s backpack or character.

Do you know where the object is coming from? You could use the ChildRemoved event if so.

https://developer.roblox.com/en-us/api-reference/event/Instance/ChildRemoved

Assuming the object is being moved from one instance to another.

In that case use AncestryChanged on the object and check its new parent

local Player = game:GetService("Players").LocalPlayer
Tool.AncestryChanged:Connect(function(Child, Parent)
	if Parent == Player.Backpack then
		-- Code
	elseif Parent == Player.Character then
		-- Other code
	end
end)

if that object does not have another optional parent, it means that it is in the other.

So there wouldn’t be a way to do this via a script that isn’t a child of the tool?

You could check when a child of the target parents is added or removed, but AncestryChanged in the tool is easier.

If you keep a general dictionary of existing tools, then you can write a custom property like that easily storing its past parent(s).