While true loop running faster with an fps unlocker

You need something more complicated, then.

Flip your thinking around: What happens if one frame takes a whole second to render? Does your code handle that?

You need a way to decouple the number of parts you draw from the number of frames.

For example (this isn’t tested, but it demonstrates the concept – I tried to name variables well so you can tell what they are):

local STUDS_PER_SECOND = 100 -- how many studs the lightning flies in a second
local SEGMENT_LENGTH = 4 -- how long each segment is

local function Fire()
    local alreadyDrawn = 0
    local position = 0
    
    while true do -- need some condition here

    	-- get the time elapsed
        local dt = game:GetService("RunService").Heartbeat:Wait()

        -- the next position to jump to
        local nextPosition = position + dt * STUDS_PER_SECOND

        -- get how many segments we'll need to draw this frame
        local needToDraw = math.floor(nextPosition / SEGMENT_LENGTH) - alreadyDrawn
        
        for i = 1, needToDraw do
            local segmentPosition = position + i * SEGMENT_LENGTH
            local segmentNumber = alreadyDrawn + i -- if you need it for some reason

            -- draw segment using segmentPosition as the position
        end

        position = nextPosition
        alreadyDrawn += needToDraw
    end
end
2 Likes