1 | Object = game.Workspace.part -- Defining the part |
2 | Backup = Object:Clone() -- Cloning the part |
3 |
4 | local find = workspace:FindFirstChild( "part" ) -- Trying to find the part if it exists. |
5 | if not find then -- Fires the command below if the part does not exist. |
6 | Backup.Parent = game.Workspace -- The command to be fired. |
7 | 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.
The problem here is that it only checks once. You need to bind this to an event like so:
1 | workspace.ChildRemoved:Connect( function (child) |
2 |
3 | end ) |
We also need to make sure the clone's parent is not workspace (make it a local):
1 | local Backup = workspace.part:Clone(); |
2 | 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:
1 | workspace.ChildRemoved:Connect( function (child) |
2 | Backup:Clone().Parent = workspace; |
3 | end ) |