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

Please help! I need to know how to clean a beam up after I shot it?

I am making this beam script (which you might know from previous questions) which creates a line of parts (Balls). But when I try to destroy them after they shoot, the beam stops after a quarter of it has been shot out. Help pls! script:

player = game.Players.LocalPlayer
mouse = player:GetMouse()
mouse.KeyDown:connect(function(key)
		key = key:lower()
	if key == "f" then
		wait(0.5)
		for i = 3,60 do
 wait()
            earth = Instance.new("Part",workspace)
			earth.Shape = "Ball"
            earth.Size = Vector3.new(1,1,1)
            earth.CanCollide = false
            earth.BrickColor = BrickColor.new("Bright red")
            earth.Anchored = true
            earth.CFrame = player.Character.Torso.CFrame * CFrame.new(0,0,-5+-i) * CFrame.fromEulerAnglesXYZ(math.random(),math.random(),math.random())
            player.Character.Torso.Anchored = true
            my = game.Lighting.Script:Clone()
            my.Parent = earth
		end
		player.Character.Torso.Anchored = false
end
end)

1 answer

At the end add:

wait(1)
for i, v in pairs(workspace:GetChildren()) do
	if v then
		if v.Name == 'earth' and v.className == 'BasePart' then
			v:remove()
		end
	end
end

-- would be better if the parts are created inside the char, so that if anything is named 'earth' it does not get deleted.

2 comments

0

But, when I tested it it only removes the first block of the beam... This script shoots out a bunch of randomly rotated blocks in a line. So the farthest one only gets removed.

0

Oh, I see what you mean. Let me show you how. Edited script.

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