Parent.Changed not Firing?

Hey, so I’m just trying to connect a function when this script’s parent (Tool) is cloned and given to a player but it doesn’t seem to work.

My Code:

local Tool = script.Parent

Tool.Parent.Changed:Connect(function()
	
	-- Code Stuff
	
end)

Hierarchy:
image

All I’m doing is cloning the Tool (located in ServerScriptService) and changing its parent, yet the Parent.Changed doesn’t fires. Your help is appreciated!

use Tool.AncestryChanged instead

1 Like
local Tool = script.Parent

Tool:GetPropertyChangedSignal("Parent"):Connect(function()

-- code

end)
2 Likes

I tried it, doesn’t affect the outcome.

Try my script next and then see.

Hmm, it doesn’t seem to work either… Edit: Would cloning the tool affect this signal in any way?

As long as the script is in the tool, the event should fire for its own clone.

Tool.Parent:GetPropertyChangedSignal("Parent"):Connect(function()
	
	print("Changed;")
	
end)

It still doesn’t fire.

Maybe try @AC_Starmarine’s code but put it into local script.

1 Like

Still nothing. Maybe there’s another way I could detect when the tool is given to a Player? I mean I know I could use some events but I would’ve thought there was a simpler way to do it.

There is some strange functionality with part.changed and part parent detection. I was testing in studio aswell. Try this, if this doesn’t work than tell me the use of the parent detections and what you need it for and we can work out a different strat.

local Tool = script.Parent

local prevParent = Tool.Parent

Tool.Changed:Connect(function()
	if Tool.Parent ~= prevParent then
		prevParent = Tool.Parent
		print("put code here for parent chage.")
	end
end)
2 Likes

Still not getting anything back.

So are you trying to detect when the tool is given to a player or different player?

Either/or. This Tool is droppable so it needs to detect when it is initially cloned from ServerStorage and when it’s picked up.

Hmm, doing some testing right now and I noticed something. When it’s cloned, it doesn’t run the script until after the parent’s already changed. Meaning it doesn’t run until the player gets it.

Heres the clone script,

local cd = script.Parent.ClickDetector
local gun = game.ServerScriptService.AT_ScriptService.WeaponStorage["M16_Rifle"]

cd.MouseClick:Connect(function(Plr)

     local c = gun:Clone()

     c.Parent = Plr.Character

end)

I guess I “sort of” found a way around it. If I change the code to something like,

local IsPlr = PlrService:GetPlayerFromCharacter(Tool.Parent)
if IsPlr then
	
	print("Changed;")
	
end

I can get it to print out, but I still feel like I should’ve been able to use those other, more reliable methods.

Maybe it’s because Studio is experience a little… trouble now. I’ve got some long load times and keep spawning in as a “Default Character”

This doesn’t work because this roughly translates to:

  • Get the tool’s current parent
  • Subscribe to it’s Changed event

What you really want is to know when the tool has changed parents.
You need to use AncestryChanged, like SelfDeclared said:

script.Parent.AncestryChanged:Connect(function(child, parent)
    print(child:GetFullName(), "got a new parent", parent:GetFullName())
end)


Just make sure to check that child is the same as tool. Additionally, make sure that the variable tool is actually the Tool and not the Handle.

Already tried that, it doesn’t do anything. I’m starting to think that Studio might be having an issue right now, everytime I click Play I spawn in as a “Noob” character. What strikes me as even more weird is that the Event.Fire() that I set off in the Parent.Changed Code block, fired the event but it didn’t print the line above it…

1 Like