Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do I regen a part after detecting that it is gone?

Object = game.Workspace.part -- Defining the part
Backup = Object:Clone() -- Cloning the part

local find = workspace:FindFirstChild("part") -- Trying to find the part if it exists.
if not find then -- Fires the command below if the part does not exist.
	Backup.Parent = game.Workspace -- The command to be fired.
end -- Ending.

Code block and thats all I have worked out but it still dont work.^

It is to regen a part if it is gone. Please help me correct it.

1 answer

The problem here is that it only checks once. You need to bind this to an event like so:

workspace.ChildRemoved:Connect(function(child)

end)

We also need to make sure the clone's parent is not workspace (make it a local):

local Backup = workspace.part:Clone();
Backup.Parent = game:GetService("ReplicatedStorage");

Now we need to detect if the child that was removed was the part and then make a clone to regen it:

workspace.ChildRemoved:Connect(function(child)
	Backup:Clone().Parent = workspace;
end)

1 comment

0

If I put "LOCAL" in front of a variable it is not "workspace" but what do you mean by that , that it is not "workspace"?

This discussion is preserved as it was. New answers, comments, and votes are closed.