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)
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.
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.
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.