Solutions for a Finish Line

Hi there.

I’m looking to make a race minigame (running, not cars) and I’m trying to figure out how I would be able to place players into positions based on where they finished (1st, 2nd, 3rd, etc.) upon crossing the finish line. I’m fairly stuck and can’t think of many (or any) solutions to this problem.

Thank you.

Add them to an array. The first 3 values in that array are the 1st, 2nd and 3rd.

1 Like

Seems like it could’ve been a bit more simple than I imagined but I’m still fairly new to scripting. Thanks a ton!

Are you wanting to count their race times as well? How are you planning on calculating who’s in first, second, or third?

Yeah, I’m counting their times as well. The race is a sprint so it’s not like there will be laps or anything. As for accurately gathering their times as they finish, I’m still trying to figure out how I’d be able to capture it while the race continues (1st place finishes first and the time is captured but time keeps going for the rest to finish, if you get what I’m saying.).

Funny, I just finished an entire system just like that.

Here’s some ideas - let me know if you have any questions.

You could have a main script, that will act as the “CPU” of the racing system. Here you can make a table that will store the players’ names and race times. Something like this:

local playerTable = {
    {Name = "Player1", Time = 3.125},
    {Name = "Player2", Time = 4.359}
    -- etc. etc.
}

And for counting, here’s a good way to do it that worked for me very accurately. So you’d have a race time value for each player, and start counting when a boolean RaceInProgress becomes true, signaling to start the race (however you want to do it).

local startTime = tick()
while RaceInProgress.Value == true do
	game:GetService("RunService").Heartbeat:Wait()
	RaceTime.Value = tick() - startTime
end

Let me know how things go eventually, and if you have any questions. I don’t want to hand you over an entire system, that’d just be more of a negative impact to you and your learning more than anything. But if there’s something specific in the racing system you’re trying to develop that you need help with at some point, feel free to let me know, or make a post on devforum of course.

1 Like

Thank you so much for this! It’s a really big help, can’t thank you enough.

1 Like