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

How do make an part regenerate automatically after a few seconds?

Asked by 4 years ago

Like when u wait for awhile then the part comes back after being destroyed.

2 answers

Log in to vote
0
Answered by 4 years ago

You can wait for the part's Parent to change. And then clone it and replace it after a few seconds. Here's what I'd do

function regen(part, seconds)
    local origin = part.Parent
    part:GetPropertyChangedSignal("Parent"):Connect(function(parent) -- Part was moved
        local clone = part:Clone() -- Save the part properties
        wait(seconds) -- Wait a few seconds
        if origin and clone and (not part or not part.Parent) then -- If part was destroyed then
            clone.Parent = origin -- put the clone back
            regen(clone, seconds)
        end
    end)
end
regen(workspace.Part, 2) -- Regenerate "Part" after 2 seconds
0
But if I removed it the part is gone and the script too. RebornedSnoop 175 — 4y
0
I mean like I wanna check if the part is destroyed then it go and replace it with the clone. RebornedSnoop 175 — 4y
0
if you don’t want it destroyed, change it’s parent to nil to and then back to workspace or whatever it’s parent is ABK2017 406 — 4y
0
use lighting NSMascot 113 — 4y
Ad
Log in to vote
-1
Answered by
NSMascot 113
4 years ago

add a serverscript (plain light blue script) into the desired part

local part = script.Parent

part.Touched:Connect(function()  --Function activated when part is touched
part.Transparency = 1 --Makes part transparent
wait(5) --Waits 5 seconds, change 5 to how many seconds you want the script to wait
part.Transparency = 0--Makes part opaque 
end) -- ends the script
0
if it works, please accept answer, ty NSMascot 113 — 4y
0
I have destroyed the part like :destroy() then I want it to regen. I cant change the transparency when the part is not when there already. RebornedSnoop 175 — 4y

Answer this question