Script for regening on damage doesn't work

This script has a function that detects a broken weld, and regens the whole ship. However, nothing happens.

function delet()
    connection:Disconnect()
    wait(0.5)
local shipparent = script.Parent.Parent
local name = script.Parent.name
local clone = script.Parent:Clone()
script.Parent:Remove()
clone.name = name
clone.Parent = shipparent
end
connection = script.Parent.ChildRemoved:Connect(delet)
1 Like

Try disconnecting the signal after you run the code instead of before it.

What do you mean by that? Sorry, I’m not too familiar with the terminology.

Move this method:

connection:Disconnect()

To the bottom of the delet() function above end and below clone.Parent = shipparent

Like this?

    wait(0.5)
local shipparent = script.Parent.Parent
local name = script.Parent
local clone = script.Parent:Clone()
script.Parent:Remove()
clone.name = name
connection:Disconnect()
clone.Parent = shipparent

end
connection = script.Parent.ChildRemoved:Connect(delet)```
It's not working.

Yeah pretty much but make it more arranged like this. Readability is key.

function delet()
    wait(0.5)

    local shipparent = script.Parent.Parent
    local name = script.Parent.name
    local clone = script.Parent:Clone()
    clone.name = name
    clone.Parent = shipparent

    script.Parent:Remove()
    connection:Disconnect()
end
connection = script.Parent.ChildRemoved:Connect(delet)

Still not working :frowning:

Where’s the script located? Can you take a screenshot where it’s at?

It’s a child of the ship’s model.
image

Is it a local or server script?

Server script. I previously used a similar one to delete planes when they are damaged.

If you add a print statement in there does it print?

1 Like

I set it to print “honk” but nothing shows up.