Instance.AncestryChanged not working

  1. What do you want to achieve?
    I want to detect if the script’s parent has changed.

  2. What is the issue?
    The event (Instance.AncestryChanged) I’m using simply wont work.

  3. What solutions have you tried so far?
    I’ve browsed the devForums a little bit but none the solutions worked.
    I have also tried using Instance:GetPropertyChangedSignal(“Parent”) which doesn’t work.

Script that changes the parent (located in ServerScriptService)

local curses = game:GetService("ServerStorage"):WaitForChild("Prefabs"):WaitForChild("CurseScripts")
local curse = curses.Giant:Clone()

game:GetService("Players").PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(char)
		
		curse.Parent = plr.Curses
		
	end)	
end)

The script that is suppose to detect if the parent has changed (Stored in ServerStorage)

script.AncestryChanged:Connect(function()
	
	print("wdadjawdwadjw")
	
	local plr = script.Parent.Parent
	local char = plr.Character or plr.CharacterAdded:Wait()
	local mod = require(game:GetService("ServerStorage"):WaitForChild("Mods").CharacterResizer)
	
	mod.ResizeCharacter(char, 10)
	
end)

The script gets put into the right folder but it just doesnt trigger the event.
It doesnt print as well.

image

1 Like

Firstly, I’d suggest you do the cloning of the script in the character added event itself or what will end up happening is the script getting reparented each time any player’s character is added to workspace. I think the reason why the event isn’t triggering is because its getting parented to the player’s character and the script doesn’t start running till it’s parented to an instance which is why the event isn’t firing.

1 Like