How to lock parent property

  1. What do you want to achieve? I want to know if we can lock parent property

  2. What is the issue? Idk how to answer this

  3. What solutions have you tried so far? I tried GetPropertyChangedSignal() but it gets warn

I want to lock parent property of something because i dont want to another developers delete my Instance

I tried to do

Instance:GetPropertyChangedSignal("Parent"):Connect(function()
	Instance.Parent = workspace
end

but it gets warn

You can’t change parent of an instance too fast

Instance:GetPropertyChangedSignal("Parent"):Connect(function()
    task.wait()
	Instance.Parent = workspace
end

but i want to change the parent quickly before :Destroy() called or something

Well theres no other method, you can’t stop a Destroy being called

Maybe just do

Instance.Destroying:Connect(function()
  Instance:Clone().Parent = workspace
end)

it was not firing when destroying the part

Instance:GetPropertyChangedSignal("Parent"):Connect(function()
	if instance.Parent ~= game.Workspace then
 Instance.Parent = workspace
end
end

because you were essentially creating an infinite loop.

just note, you don’t need to write game.Workspace when you can directly write workspace.

i got warn again

image

Maybe add his code with an task.wait again?

There’s no point yielding? It won’t loop.

i want to prevent :Destroy() on instance

Can’t you use the ChildRemoved or DescendantRemoving events and place that Instance again?

workspace.ChildRemoved:Connect(function(removedChild)
    removedChild:Clone().Parent = workspace
end)

The code above behaves as how the Parent property is locked using :Destroy() method.

Perhaps, another temporary method would be to record the Instance somewhere else with its properties serialized in a script and when the Instance gets removed from the Workspace, the script registered the serialization would use the ChildRemoved event and re-insert that Instance. Like as follows:

local part = workspace.Part

local serialization = {
    [1] = part.CFrame --etc
}

workspace.ChildRemoved:Connect(function(removedChild)
    for i, v in ipairs(serialization) do
        local clone = removedChild:Clone()
        clone.CFrame = v
    end
end)
1 Like

Then you would need to serialize the model because there is no good way to do this.

Well you shouldn’t? If you don’t want other developers to delete your instances then save the game to a file or just hire trusted developers.

Instance.AncestryChanged:Connect(function(parent)
	if parent ~= workspace then
       wait(1)
       Instance.Parent = workspace
    end
end)

you get a parent property locked error on :Destroy() called object

Here’s an code

local Instance = urpartpath
local clonedinstance = Instance:Clone()
local Instanceparent = Instance.Parent
Instance:GetPropertyChangedSignal("Parent"):Connect(function()
	if instance.Parent ~= game.Workspace then
task.wait()
 Instance.Parent = workspace
end
end) --ratiusrat's code.

Instanceparent.ChildRemoved:Connect(function()
if not Instance ~= nil then
clonedinstance.Parent = Instanceparent
Instance = clonedinstance
clonedinstance = Instance:Clone()
end
end)

It’s not gonna work properly but it should give you an idea

There’s literally no point yielding in the parent change event. It literally won’t loop.

If you don’t yield an error will pop in as @OP said