Here is the script so far -
while true do wait(300) StatName = "Kills" Amount = 0 wait(.1) Player = game.Players:GetPlayerFromCharacter(workspace[PlayerName]) StatLeaderboard = Player.leaderstats[StatName] StatName = "Deaths" Amount = 0 wait(.1) Player = game.Players:GetPlayerFromCharacter(workspace[PlayerName]) StatLeaderboard = Player.leaderstats[StatName] end
I want to reset the leader stats every 5 min for all players and the stats are Kills and Deaths
The script isn't working though and I dont know why, can you help me
Also if the script does look terrible, I only started a year ago
I rewrote this to give you a better idea of how it should look. You can add some more if checks but if the rest of your code is working correctly you shouldn't have any errors.
Your code has several issues, but most importantly this 'Amount = 0' doesn't do anything. You need to create the values on entry, not at some interval.
--a simple function to iterate all players turning the specified objects value to 0, this is more flexible since it allows for any amount, any stat(inside leaderstats), and any group of players function resetStat(players,stat,amount) for i,v in pairs(players) do v.leaderstats[stat].Value = amount end end --this adds the leaderstats folder and corresponding values when player joins the game game.Players.PlayerAdded:Connect(function(Player) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = Player local Kills = Instance.new("IntValue") Kills.Name = "Kills" Kills.Parent = Player.leaderstats local Deaths = Instance.new("IntValue") Deaths.Name = "Deaths" Deaths.Parent = Player.leaderstats end) --much cleaner, right? while wait(300) do local players = game:GetService('Players'):GetChildren() resetStat(players, 'Kills', 0) resetStat(players, 'Deaths', 0) end