Problems with saving an array into DataStorage please Help??
Asked by
6 years ago Edited 6 years ago
Hi how are you, i have problem and is saving Arrays with datastore and for that i look for the subject, and I found that with json could be saved arrays then i create this script.
02 | local DataStore = game:GetService( "DataStoreService" ) |
03 | local Data = DataStore:GetDataStore( "TestData4" ) |
06 | local HttpService = game:GetService( "HttpService" ) |
12 | local DecodeData = HttpService:JSONDecode(Data) |
16 | function LoadData(player) |
18 | local success, message = pcall ( function () |
19 | GetData = Data:GetAsync( "player-" ..player.userId) |
22 | local DataIsloaded = player:WaitForChild( "IsDataLoaded" ) |
29 | GetData = { 0 , 0 ,BrickColor.White(), "" , "M4" , "M9" , "None" , "None" } |
31 | print ( "Sucessfuly Created Data For " ..player.Name) |
36 | data [ player.userId ] = GetData |
42 | function SaveData(player,Reason) |
44 | local EncodeData = HttpService:JSONEncode(DecodeData) |
47 | if Reason = = "Leaving" then |
48 | Data:SetAsync( "player-" ..player.userId,EncodeData) |
49 | data [ player.userId ] = nil |
50 | elseif Reason = = "Save" then |
51 | Data:SetAsync( "player-" ..player.userId,EncodeData) |
54 | print ( "Saving Data For " ..player.Name) |
58 | game.Players.PlayerAdded:connect( function (player) |
63 | game.Players.PlayerRemoving:connect( function (player) |
64 | SaveData(player, "Leaving" ) |
69 | coroutine.resume(coroutine.create( function () |
71 | for a,player in pairs (game.Players:GetChildren()) do |
72 | if data [ player.userId ] ~ = nil then |
74 | SaveData(player, "Save" ) |
And I Got This Problem on the ouput:
- Can't parse JSON
- Stack Begin
- Script 'ServerScriptService.GameData', Line 27
- Stack End`
Please Help i Need This urgent and sorry if the JSON code, it´s bad i´m new with that.
Thank you for the Help