🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Trouble updating a Roblox leaderboard

Started by
1 comment, last by Tom Sloper 3 years, 6 months ago

(UPDATED) PROBLEM:

I am attempting a simple task of updating a player's all-time win totals. Here is the code I used based on tutorials I have watched:

local DataStoreService = game:GetService("DataStoreService")
 local myDataStore = DataStoreService:GetDataStore("myDataStore")

 game.Players.PlayerAdded:Connect(function(player)
     local leaderstats = Instance.new("Folder")
     leaderstats.Name = "leaderstats"
     leaderstats.Parent = player

     local wins = Instance.new("IntValue")
     wins.Name = "Wins"
     wins.Parent = leaderstats
    
     local data
     local success, errormessage = pcall(function()
     data = myDataStore:GetAsync(player.UserId.."-wins")
     end)

     if success then
         wins.Value = data
     else
         print("There was an error while getting your data")
         warn(errormessage)
     end
 end)

 game.Players.PlayerRemoving:Connect(function(player)

     local success, errormessage = pcall(function()
         myDataStore:SetAsync(player.UserId.."-wins",player.leaderstats.Wins.Value)
     end)

     if success then
         print("Player Data successfully saved")
     else
         print("There was an error when saving data")
         warn(errormessage)
     end
 end)

When a player wins a round in my game, I have been able to identify the winner via a variable called 'winning player.' So the command I have tried to update the player's win total is as follows:

 game.Players.winningplayer.leaderstats.Wins.Value = game.Players.winningplayer.leaderstats.Wins.Value + 1

THE PROBLEM

Unfortunately when this happens I get an error saying: winningplayer is not a valid member of Player "Players"

Would really love help with this. Many thanks!

Advertisement

This is not a Game Design question, so this question has been moved to a programming forum. The Game Design forum is only for questions/discussions about the design of games.

-- Tom Sloper -- sloperama.com

This topic is closed to new replies.

Advertisement