Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago
Edited 4 years ago
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

Log in to vote
0
Answered by 4 years ago

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)
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"? RebornedSnoop 175 — 4y
Ad

Answer this question