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

script that destroys a part of the building and re-gens but, it wont re-gen how do i fix?

this is a script where a ball hits a building and destroys the pats it hit and a moment later the parts that got hit by the ball regen/remake them self but it wont work idk why no errors.

Destroy script

script.Parent.Touched:Connect(function(hit)
	
if hit:IsA("Terrain") then
		print("mui")
			else 			
		
	for _,i in  pairs(hit.Parent:GetChildren()) do
		if i:IsA("BasePart") then
			
		hit:BreakJoints()
		hit.Anchored = false
		hit.Velocity = Vector3.new(23,90,13)
		hit.RotVelocity = Vector3.new(141.9,90,121)
	
		end
		wait()
			hit:Destroy()
			end
end

end)

Re-gen script

script.Parent.Touched:Connect(function(hit)
	
if hit:IsA("Terrain") then
		print("m3i")
			else 

		
	for _,i in  pairs(hit.Parent:GetChildren()) do
		if i:IsA("BasePart") then
		local clo = hit:clone()					
local ipos = hit.CFrame	
		clo.Parent = workspace
	clo.CFrame = ipos		
		end
	
			end
end

end)

-- i tried to put both in the same script but it wont work

2 comments

0

Honestly, I think that placing them in seperate scripts will mess up the sequence of the result, so the regen may have happened before the part destroyed itself. Seeing that you have waits in the Destroy script and the regen does not, I think it is likley that this is what happened. My conclusion to you is to add wait(1) in the re-gen script before line 10.

0

The parts get destroyed but it wont regen

1 answer

Honestly, I think that placing them in seperate scripts will mess up the sequence of the result, so the regen may have happened before the part destroyed itself. Seeing that you have waits in the Destroy script and the regen does not, I think it is likley that this is what happened. My conclusion to you is to add wait(1) in the re-gen script before line 10.

P.S sorry I accidently added the post comments as well :]... I am new to this so bear with me :)

1 comment

0

did not work

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