So I had someone help me make a working leaderboard script where whenver a player dies in any way He/She will get 10 Tokens "Money" and +1 to the Death value.. But for some reason I am getting this problem where it says "leaderstats is not a valid member of Player" and the leaderboard does not work correctly as once it will add values and then when I test the game again it will not add any values at all and they would just stay at 0.. And that just keeps changing each time I test it. I would really appreciate it if someone could help me fix this please!
This is the script that adds the values for each time a player dies.
local players = game:GetService("Players") players.PlayerAdded:Connect(function(plr) local deaths = plr.leaderstats.Deaths local tokens = plr.leaderstats.Tokens plr.CharacterAdded:Connect(function(char) char.Humanoid.Died:Connect(function() deaths.Value = deaths.Value + 1 tokens.Value = tokens.Value + 10 end) end) end)
leaderstats does NOT exist by default, you have to create a folder called leaderstats and add values (such as NumberValues) into this folder
local players = game:GetService("Players") players.PlayerAdded:Connect(function(plr) local leaderstats = Instance.new("Folder") leaderstats.Name = "leaderstats" leaderstats.Parent = plr local deaths = Instance.new("IntValue") deaths.Name = "Deaths" deaths.Parent = leaderstats local tokens = Instance.new("NumberValue") tokens.Name = "Tokens" tokens.Parent = leaderstats plr.CharacterAdded:Connect(function(char) char.Humanoid.Died:Connect(function() deaths.Value = deaths.Value + 1 tokens.Value = tokens.Value + 10 end) end) end)