Basically i have a script as follow to modify the laps, however after calling StartRace function, it find the old laps. I tryed to call the modify function to see if it modified the laps and it did but when i printed the table in startrace it wasn’t updated.
Update Laps Function:
-- Set custom laps for each race
function module:ChangeLaps(race:string,laps:number)
if not race then
return
end
if not laps then
return
end
for i,v in KnowRacesData do
if v.Name == race then
print(v.Laps)
end
end
for i,v in KnowRacesData do
if v.Name == race then
v.Laps = laps
print("change success")
end
end
for i,v in KnowRacesData do
if v.Name == race then
print(v.Laps)
end
end
end
Table:
-- Data
local KnowRacesData = {
{
Name = "Off Road",
ExpirationTime = 270,
Laps = 4,
Reward = 2000,
CheckpointMaxDistance = 260
},
{
Name = "Drag Race",
ExpirationTime = 150,
Laps = 1,
Reward = 200,
CheckpointMaxDistance = 500,
}
}
Start Race:
function module:StartRace(race:string,players,vehicles)
local FinalTimes = {}
local Times = {}
-- Change to false to stop race and put anyone DNF
RunningRaces[race] = true
UserLeavingConnection = game.Players.PlayerRemoving:Connect(function(player)
if not player then
return
end
if table.find(players,player) then
table.remove(players,table.find(players,player))
if #players == 0 then
self:EndRace(race,players,vehicles)
end
end
end)
UserDeadConnection = UserDied.Event:Connect(function(player)
print(player)
if not player then
return
end
if table.find(players,player) then
table.remove(players,table.find(players,player))
end
end)
local success,errorm = pcall(function()
if not race then
return
end
if not players then
warn("No players")
return
end
if not vehicles then
warn("No vehicles")
return
end
local racedata = false
for i,racedatav in KnowRacesData do
for ii,v in racedatav do
print(ii,v)
end
if racedatav.Name == race then
racedata = racedatav
break
end
end
Prints: