local AllPositions = FindAllPositions()
local AmountOfRacers = #game.Players:GetPlayers()
for _,currentPlayer in pairs(game.Players:GetPlayers()) do
local PositionOfThisPlayer = FindPlayerPosition(currentPlayer)
local LapOfThisPlayer = FindPlayerLap(currentPlayer)
--for i,v in pairs(AllPositions) do
--if (PositionOfThisPlayer == v) then
--end
--end
local MaxValue = math.min(table.unpack(AllPositions)) -- 1 player position
local PlayerPos = math.ceil((PositionOfThisPlayer))%MaxValue)
table.insert(UI,{Player = currentPlayer,Position = PlayerPos})
end
Hi guys, that’s basically a script I am making that basically works by racing, the one that is first, wins, I am using ProgressTracker by @Zomebody
It basically returns a Number from 0 to 1
Code works perfectly, but, how could I add into this, more value to the player that has more Lap?
‘LapOfThisPlayer’ is the lap player is using
local AllPositions = FindAllPositions()
local AmountOfRacers = #game.Players:GetPlayers()
for _,currentPlayer in pairs(game.Players:GetPlayers()) do
local PositionOfThisPlayer = FindPlayerPosition(currentPlayer)
local LapOfThisPlayer = FindPlayerLap(currentPlayer)
local MaxValue = math.max(table.unpack(AllPositions)) -- the pladyer that is going first
local PlayerPos = math.ceil(((PositionOfThisPlayer)%MaxValue))
PlayerPos = PlayerPos and PlayerPos or 0
table.insert(UI,{Player = currentPlayer,Position = PlayerPos})
end
I changed and it works the same.
What I mean is; if player Lap (LapOfThisPlayer) is higher then other players, he gets next position, like in race games
Your explanation is rough, but I think what you are looking for is table.sort()? Maybe something like…
local players = game.Players:GetPlayers()
table.sort(players, function(a, b)
return FindPlayerLap(a) > FindPlayerLap(b)
end)
local MaxValue = math.max(table.unpack(FindAllPositions()))
for _, pl in pairs(players) do
table.insert(UI, {Player = pl, Position = FindPlayerPosition(pl) % MaxValue})
end
This would insert players into the table ‘UI’ first if they have a higher ‘LapOfThisPlayer’. This is the best I can do based on your explanation + code. I’m not sure how ‘PlayerPosition’ factors into it at all.
Some side notes:
No need to do this inside the loop, the table ‘AllPositions’ is not changing. I have placed it outside the loop.
Pointless statement because the line above it will error if ‘PlayerPos’ is nil.
Haven’t looked at the Progress Tracker code, but if it is giving a decimal value from 0 to 1 that tells where a player is along the track (0=start, 1=end), then you should be able to just keep a separate lap counter for each player (in a table) and add that value to the Progress Tracker decimal (for a player) to get a total position score.
For example:
player 1: 0.5 around the track on lap 3
player 2: 0.75 around the track on lap 3
player 3: 0.25 around the track on lap 4
p1 total = 0.5 + 3 = 3.5
p2 total = 0.75 + 3 = 3.75
p3 total = 0.25 + 4 = 4.25
p3 is winning based on laps even though only 0.25 around the track. Once you have those total scores for all players you can sort to find who is in first, second, etc.
It makes sense the table.sort tho, but how would that count by lap? or by who has highest points when lap’s 1
Right now it’s not D: (with your code)
Sorry for bad explaining.
So basically, the player that has higher lap has first position or if everyone is in same lap, the one that has better (FindPLayerPosition(pl)) that returns number from 0 to 1 with progress , is first
local players = game.Players:GetPlayers()
for i,v in pairs(players) do
RefreshPosition(v,Pos)
end
local MaxValue = math.max(table.unpack(FindAllPositions()))
table.sort(players, function(a, b)
return FindPlayerLap(a) < FindPlayerLap(b)
end)
for i,v in pairs(players) do
table.insert(UI,{Player = v,Position = math.ceil(FindPlayerPosition(v)%MaxValue)})
end
Alright now this is a description we can actually work with. So basically their position is either based on having higher lap count or it’s based on the return of ‘FindPlayerPosition’. You could do all of that in the table.sort:
local players = game.Players:GetPlayers()
table.sort(players, function(a, b)
local aLapCount = FindPlayerLap(a)
local bLapCount = FindPlayerLap(b)
if aLapCount == bLapCount then
return FindPlayerPosition(a) > FindPlayerPosition(b)
else
return aLapCount > bLapCount
end
end)
for i, v in pairs(players) do
table.insert(UI, {Player = v, Position = i})
end
local Players = game.Players:GetPlayers()
table.sort(Players, function(a, b)
return FindPlayerPosition(a) + FindPlayerLap(a) > FindPlayerPosition(b) + FindPlayerLap(b)
end)
for i,v in pairs(Players) do
table.insert(UI,{Player = v,Position = i})
end
But I’ll still mark you as solution since you helped me think about table.sort and give me idea to do this