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

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

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

2 answers

✓ Accepted answer

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

4 comments

0

But if I removed it the part is gone and the script too.

0

I mean like I wanna check if the part is destroyed then it go and replace it with the clone.

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

0

use lighting

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

2 comments

0

if it works, please accept answer, ty

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.

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