hello all! i’ve been working on a soccer game with a friend, me taking the scripting role, however, i’m at a roadblock, i need to handle the resetting of the “Goals” leaderstat after a match ends (i’m using it as a temporary stat to measure how many goals each player has hit), my issue is with how i’d do it, right now, i have this function that’s meant to reset both the team stats (i have numbervalues inside each team), as well as the leaderstats, however, it only resets the team stats, without resetting the leaderboard stats, here is my function
local teams = game.Teams:GetChildren()
local players = game.Players:GetChildren()
-- two variables defined earlier in the script
local function resetStats()
for i, player in ipairs(players) do
player.leaderstats.Goals.Value = 0
print("cleared leaderstats for player "..player.Name)
end
for i, team in ipairs(teams) do
team.Points.Value = 0
end
end
the one resetting the teams score works just fine, and does what it should do, however, the one resetting leaderstats does absolutely nothing, which sucks, since i’m using this to reset everyone’s stats to prepare a new match from scratch.
(for context, i’m a bit new to messing with leaderboards, so i might be a little dumb with this, sorry if anyone has to suffer from this)
does anyone know how to help me with this situation? i’m not using datastores, or any form of data saving, if you couldn’t tell. thanks all!
Oh, you should remove the players variable. If new players join, they won’t be apart of that list. So instead, use game.Players:GetPlayers() directly in pairs.
the problem is when it gives this value at the beginning of the game (or at any time), it takes the instances of the current players
Remove :GetChildren() and use inside pairs()