Answered by
0_2k 496
5 years ago
The value when joining needs to be set to a table in order within the DataStore. The value when leaving needs to be set as an array. Lastly, in the if suc, else
statement, don't just print, Run the GetAsync.
01 | datastore = game:GetService( "DataStoreService" ) |
02 | WV = datastore:GetDataStore( "WinsValue" ) |
03 | game.Players.PlayerAdded:Connect( function (player) |
04 | local folder = Instance.new( "Folder" ) |
05 | folder.Parent = player |
06 | folder.Name = "leaderstats" |
07 | local wins = Instance.new( "IntValue" ) |
12 | local suc,err = pcall ( function () |
13 | winsvalue = WV:GetAsync(player.UserId) |
16 | wins.Value = winsvalue [ 1 ] |
18 | local toSave = { wins.Value } |
19 | print ( "There was an error while trying to get data" ) |
23 | game.Players.PlayerRemoving:Connect( function (player) |
24 | local suc, err = pcall ( function () |
25 | WV:SetAsync(player.UserId, { player.leaderstats.Wins.Value } ) |
28 | print ( "Successfully stored data" ) |
31 | print ( "There was an error while trying to store data" ) |