Player data for "leaderstats" won't save on my world, anyone know a fix?
01 | local DSServ = game:GetService( "DataStoreService" ) |
02 | local plrServ = DSServ:GetDataStore( "PlrLeaderboard" ) |
04 | game.Players.PlayerAdded:Connect( function (client) |
05 | local leaderstats = Instance.new( "Folder" ) |
06 | leaderstats.Name = "leaderstats" |
07 | leaderstats.Parent = client |
09 | local cash = Instance.new( "IntValue" ) |
11 | cash.Parent = leaderstats |
15 | game.Players.PlayerRemoving:Connect( function (client) |
16 | local userId = client.UserId |
17 | if userId = = 316061618 then |
18 | print ( "THE OWNER IS HERE!" ) |
19 | client.leaderstats.Cash.Value = client.leaderstats.Cash.Value + 1000 |
21 | local success, errorMessage = pcall ( function () |
22 | plrServ:SetAsync(client.UserId.. "-cash" , client.leaderstats.Cash.Value) |
26 | print ( "Successfully saved data!" ) |
28 | print ( "An error occured attempting to save data" ) |
This may seem like a lot, but I'm just trying to save player data to set up a currency system for a game (the world has API for Studio turned on). I made a mechanic that adds 1000 to my currency whenever I leave the game (it checks for my UserId and adds it if the current player's Id and mine match, meaning it's me). I don't know what the problem is, but it won't save the data. Please let me know what the problem is if you think you know. Thx