I am trying to make a racing game where players run around a track and collect items to make them go faster but i wanted to make a system that checks and says what place you are in and changes as you progress and i decided to put checkpoints around the map and when you touch it it adds a point to a value in your player.
now my problem occurs when i try to compare the values by placing them all in a table using table.insert and table.insert overwrites the previous value.
i have searched previous solutions on the forums but unfortunately none of them seem to work.
I’m a beginner at scripting any fed back on the script that i wrote would be appreciated.
– edit
i have updated to current
here is the code
local places = {
first = 0,
second = 0,
third = 0,
fourth = 0,
fifth = 0,
sixth = 0,
seventh = 0,
eighth = 0
}
local plrPlace = {
firstPlr = 0,
secondPlr = 0,
thirdPlr = 0,
fourthPlr = 0,
fifthPlr = 0,
sixthPlr = 0,
seventhPlr = 0,
eighthPlr = 0
}
while wait()do
local Vals = game.Player.points:GetChildren()
for _ ,value in pairs(Vals) do
local NV = value.Value
table.insert(places,1,NV)
table.sort(places)
local plrs = game.Players:GetChildren()
for _,plr in pairs(plrs)do
if plr.Game.Point.Value >= places.first then
places.first = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.second then
places.second = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.third then
places.third = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.fourth then
places.fourth = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.fifth then
places.fifth = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.sixth then
places.sixth = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.seventh then
places.seventh = plr.Game.Point.Value
elseif plr.Game.Point.Value >= places.eighth then
places.eighth = plr.Game.Point.Value
end
for _ ,value in pairs(Vals) do
local NV = value.Value
table.insert(plrPlace,1,NV)
table.sort(plrPlace)
local plrs = game.Players:GetChildren()
if plr.Game.Point.Value == places.first then
plrPlace.firstPlr = plr
print("done")
elseif plr.Game.Point.Value == places.second then
plrPlace.secondPlr = plr
print("done2")
elseif plr.Game.Point.Value == places.third then
plrPlace.thirdPlr = plr
elseif plr.Game.Point.Value == places.fourth then
plrPlace.fourthPlr = plr
elseif plr.Game.Point.Value == places.fifth then
plrPlace.fifthPlr = plr
elseif plr.Game.Point.Value == places.sixth then
plrPlace.sixthPlr = plr
elseif plr.Game.Point.Value == places.seventh then
plrPlace.seventhPlr = plr
elseif plr.Game.Point.Value == places.eighth then
plrPlace.eighthPlr = plr
end
end
end
end
```