Datastore is not saving data? [PLEASE HELP]
Asked by
4 years ago Edited 4 years ago
Hey guys, im having an issue with my datastore. So i plan on saving alot of data, and i want to do it on one key, the player UserId. To do this, i make a table and use Http Service to encode and decode it (which works, i tested it), but it appears it does not save correctly. Here is the code:
02 | local Players = game:GetService( "Players" ) |
03 | local DataStoreService = game:GetService( "DataStoreService" ) |
04 | local Http = game:GetService( "HttpService" ) |
07 | local Data = DataStoreService:GetDataStore( "Data" ) |
09 | Players.PlayerAdded:Connect( function (Player) |
11 | local leaderstats = Instance.new( "Folder" ) |
12 | leaderstats.Name = "leaderstats" |
13 | leaderstats.Parent = Player |
15 | local Coins = Instance.new( "IntValue" ) |
17 | Coins.Parent = leaderstats |
19 | local House = Instance.new( "IntValue" ) |
24 | local PlotType = Instance.new( "StringValue" ) |
25 | PlotType.Name = "PlotType" |
26 | PlotType.Parent = Player |
28 | local HouseModel = Instance.new( "StringValue" ) |
29 | HouseModel.Name = "HouseType" |
30 | HouseModel.Parent = Player |
35 | PlotType = PlotType.Value |
39 | local UserId = Player.UserId |
40 | while Success = = false do |
41 | local suc,err = pcall ( function () |
42 | Encode = Data:GetAsync(UserId) |
47 | print ( "Error loading player data" ) |
52 | local _Success = false |
53 | while _Success = = false do |
54 | local suc,err = pcall ( function () |
55 | Decode = Http:JSONDecode(Encode) |
62 | Players.PlayerRemoving:Connect( function (Player) |
63 | local leaderstats = Player.leaderstats |
64 | local UserId = Player.UserId |
66 | Coins = leaderstats.Coins.Value, |
67 | PlotType = Player.PlotType.Value |
71 | while _Suc = = false do |
72 | local Success,Error = pcall ( function () |
73 | Encode = Http:JSONEncode(SavedData) |
80 | while Success = = false do |
81 | local suc,err = pcall ( function () |
82 | Data:SetAsync(UserId,Encode) |
88 | print ( "There was an error saving data" ) |