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

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

Asked by 9 years ago

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

Log in to vote
0
Answered by 9 years ago

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.
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. Operation_Meme 890 — 9y
0
Oh, I see what you mean. Let me show you how. Edited script. killerkill29 35 — 9y
Ad

Answer this question