GetPropertyChangedSignal() not working

This script is supposed to fire when i clone/change the parent of the script to another, but when i clone the script this doesn’t fire, any ideas why?

local ps = require(game:GetService("ServerScriptService").PocketScripts)
print("test1")
script:GetPropertyChangedSignal("Parent"):Connect(function()	
	
	print("test2")

	local plr = script.Parent.Parent

	for i, theScript in pairs(ps.GetChildrenWhichIsA(plr, "Script")) do
		if theScript ~= script then
			theScript:Destroy()
		end
	end

	print("nottest")
	script.Parent.Value = script.Parent.Value + 60
	print("test")

	for i = 0, script.Parent.Value, .1 do
		task.wait(.1)
		script.Parent.Value = script.Parent.Value - .1
		print(script.Parent.Value)
	end

	script.Parent.Name = "1"
	script:Destroy()
	
end)

In the output it printed “test1” but never printed “test2” after i cloned it, help would be appreciated!

1 Like

Are you changing the parent on the server?

Wdym by cloning it? :Clone() doesn’t copy connections so if you want the connection to run for the clone then you need to connect it again

The script runs again whenever you change the parent or clone it. This both prevents the event from running and makes the event unnecessary. Just get rid of it.

The script only runs after you clone it so it doesn’t run the function.

I cloned the script and set the parent to a Player

It turns out that the problem is that after i cloned it, it doesn’t run. Could this be because i set the parent as a player?

Is the script a localscript

if script:IsA("LocalScript") then
	print("bruh this minimum text thing lol")
end

Okay so turns out there’s nothing wrong with the GetPropertyChangedSignal() function, the script doesn’t work because this script is not Local Script and i set the parent into a Player, resulting in it not printing anything. Changed the script into local and now it works, thank you for the help everyone!

1 Like