Race Position Updating

I am looking at a way to keep track of race positions (1st, 2nd 3rd, etc) preferably without the use of checkpoints as I’d like the positions to update as soon as the player passes another. The game includes laps as well, so I am also not sure how I’d be able to make sure that someone on their first lap cannot overtake someone on their second or third.

I have looked through the forum for solutions but all I can find are solutions that implement checkpoints which may not be viable for my game as the maps frequently use detours and shortcuts.

I am not looking for somebody to hand me over an entire script that will magically solve all my problems, I am looking for someone who may be able to give me ideas or point me in the right direction because I am lost right now.

If using checkpoints is the only option, how would I go about using that and how would using checkpoints work with the shortcuts and detours?

I have an idea.

I would use a repetitive loop that constantly checks the difference between the current car’s position and their previously recorded car position from RunService. Then, I take that difference and add it to a variable. I would only check the difference if the car is moving, if it’s stopping or stationary I won’t count. I will do this whole process on other racing cars as well.

After I got those values synchronously, I will compare all of them and check which number is the higher than the other one and confirm their rank.

I’ll just try to code to help you understand better:

local RacingCars = {
    [Car1] = Vector3.new(0,0,0) — this value will be their previous pos, you have to code a function to get their initial position first when they started to race
    …
}

RunService.Heartbeat:Connect(function()
    local AllCarModelsTotalDistanceTravelled = {} — an empty dictionary that consists of the every car mode’s total distance travelled
    for carModel, previousPos in ipairs(RacingCars) do
        local CurrentPosition
        if carModel.IsMoving then
            CurrentPosition = carModel.Position
        else
            CurrentPosition = previousPos — if not moving, we will use their previous pos 
        end
        local Difference = CurrentPosition - previousPos
        Difference += previousPos
        AllCarModelsTotalDistanceTravelled[carMode] = Difference
    end
    GiveRanks(AllCarModelsDifferences) — this function will sort which number is bigger than the other (the biggest value(total distance travelled) is 1st.)
end)

I hope this helps.

Thanks for the reply, just thinking about the lap situation with this idea as all the courses would be circuits, or am I going down the wrong path and thinking too much into it?

Well, I’m not a geek in racing, but can you tell me what’s a circuit lol

Something like this where the course is repeated over a series of laps

Well, you then have to utilize another variable that shows however many laps they’ve been through.