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

How do I stop my part merging script from making the part grow exponentially?

Asked by
AronYstad 101
2 years ago

So I have a script that merges smoke parts (balls) to prevent lag. When I run it, it works fine at first, but then it quickly grows exponentially and makes some of the parts larger than the map. I think it might be due to the script firing in both of the colliding parts, but I'm not sure, and I don't know how to fix it. Here is the code:

repeat wait() until script.Parent.Name == "Smoke"

script.Parent.Touched:Connect(function(part)
    if part.Name == "Smoke" then
        local smoke = Instance.new("Part",game.Workspace)
        smoke.Shape = Enum.PartType.Ball
        local volume1 = ((script.Parent.Size.X/2)^3)*math.pi*4/3
        local volume2 = ((part.Size.X/2)^3)*math.pi*4/3
        local diameter = ((((volume1+volume2)*3)/(4*math.pi))^(1/3))*2
        smoke.Size = Vector3.new(diameter,diameter,diameter)
        smoke.Position = ((script.Parent.Position+part.Position)/2)-Vector3.new(0,(script.Parent.Size+part.Size)/2,0)
        smoke.Name = "Smoke"
        smoke.BrickColor = BrickColor.new("Smoky grey")
        local BodyForce = Instance.new("BodyForce",smoke)
        BodyForce.Force = Vector3.new(0,600*((smoke.Size.X/2)^3)*4/3*math.pi,0)
        smoke.TopSurface = Enum.SurfaceType.Smooth
        smoke.BottomSurface = Enum.SurfaceType.Smooth
        smoke.Transparency = 0.25
        local SmokeColorScript = game.Workspace.SmokeColorScript:Clone()
        SmokeColorScript.Parent = smoke
        local SmokeCollisionScript = game.Workspace.SmokeCollisionScript:Clone()
        SmokeCollisionScript.Parent = smoke
        local StopSmokeScript = game.Workspace.StopSmokeScript:Clone()
        StopSmokeScript.Parent = smoke
        part:Destroy()
        script.Parent:Destroy()
    end
end)

Answer this question