Script for making a circle with Beams using CurveSize

I don’t take full credit for this, got a great deal of help from him and a bit of AI.

What does this do?
As title says, makes a circle with a defined radius and vertices (amount of attachments), using beams and their CurveSize to accomplish this.

Why should I use it?
Issue with finding the correct CurveSize for a beam in a circle shape is that it has to do with bezier, so there’s some math behind it.

If you’re too lazy to do that just run the script I guess.

How to use?
Click on a part and run the script (how to). It will automatically create a circle around it of your defined radius and with the amount of vertices u want (change it in the code).

Ok so what’s the use?
Mainly for VFX, such as this type of rings. (more complex vfx example ig)

Code

local currentAngle = 0
local part = game:GetService("Selection"):Get()[1]

-- CHANGE THESE
local vertices = 4
local radius = 3
--

local maxVertices = vertices
local previousAtt = nil
local previousBeam = nil
local mainAtt = nil

while vertices > 0 do
    local att = Instance.new("Attachment")
    att.Parent = part

    local beam = Instance.new("Beam")

    if vertices == maxVertices then
        mainAtt = att
    end

    beam.Parent = mainAtt
    beam.Attachment0 = att

    if previousAtt then
        previousBeam.Attachment1 = att
    end

    previousAtt = att
    previousBeam = beam

    local pos = Vector3.new(radius * math.cos(currentAngle), 0, radius * math.sin(currentAngle))

    local tangent = Vector3.new(-pos.Z, 0, pos.X).Unit
    local normal = pos.Unit
    local up = Vector3.new(0,1,0)


    att.CFrame = CFrame.fromMatrix(pos, tangent, up, normal)

    local curve = (4/3) * radius * math.tan((2 * math.pi/maxVertices)/4)
    beam.CurveSize0 = curve
    beam.CurveSize1 = curve

    vertices -= 1

    if vertices == 0 then
        beam.Attachment1 = mainAtt
    end

    currentAngle += math.rad(360/maxVertices)
end
5 Likes

This is pretty cool, would definitely find an use for it.

1 Like