RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 10 Sep 2017 05:26 PM |
why doesnt this load my data when i rejoin
prints loaded data
local DataHandler = require(game.ReplicatedStorage.Modules.DataHandler)
game.Players.PlayerAdded:connect(function(player) DataHandler.LoadData(player) print('Loaded data')
game.Players.PlayerRemoving:connect(function(player) DataHandler.SaveData(player) end )
game.OnClose = function() for i,v in next, game.Players:GetPlayers() do DataHandler.SaveData(v) end end
|
|
|
| Report Abuse |
|
RaTheKush
|
  |
| Joined: 12 Dec 2014 |
| Total Posts: 1978 |
|
|
| 10 Sep 2017 05:29 PM |
thats in a server script
local PlayerData = game:GetService('DataStoreService'):GetDataStore('Data048')
local DefaultStats = { Stats = { Special = { ForceStop = false, Combat = 1, ExpNeeded = 83, Exp = 0, Effect = 1, NewPlayer = 1, Level =0, ItemEquipted = 0 }, Attack = { Level = 1, ExpNeeded = 83, Exp = 0, Effect = 1, PrayerExtra = 0, ExpEarned = 0 }, Strength = { Level = 1, ExpNeeded = 83, Exp = 0, Effect = 1, PrayerExtra = 0, ExpEarned = 0
}, Defence = { Level = 1, ExpNeeded = 83, Exp = 0, Effect = 1, PrayerExtra = 0, ExpEarned = 0
}, healthPoints = { Level = 10, ExpNeeded = 83, Exp = 0, Effect = 10, health = 10, PrayerExtra = 0, ExpEarned = 0 }, Woodcutting = { Level = 1, ExpNeeded = 83, Exp = 0, Effect = 1, PrayerExtra = 0, ExpEarned = 0 }, }, Inventory = { InventorySlot = 0, IVTS1 = nil, IVTS2 = nil, IVTS3 = nil, IVTS4 = nil, IVTS5 = nil, IVTS6 = nil, IVTS7 = nil, IVTS8 = nil, IVTS9 = nil, IVTS10 = nil, IVTS11 = nil, IVTS12 = nil, IVTS13 = nil, IVTS14 = nil, IVTS15 = nil, IVTS16 = nil, IVTS17 = nil, IVTS18 = nil, IVTS19 = nil, IVTS20 = nil, IVTS21 = nil, IVTS22 = nil, IVTS23 = nil, IVTS24 = nil, IVTS25 = nil, IVTS26 = nil, IVTS27 = nil, IVTS28 = nil
},
}
local PlayerStats = {}
local DataHandler = {}
LoadStats = function(Player) local UserId = Player.UserId local PlayerStats = PlayerStats[UserId] for stats,data in next, PlayerStats do local NewStat = Instance.new('Folder',Player) NewStat.Name = stats for key,val in next, data do if type(val) == 'table' then local NewFolder = Instance.new('Folder',NewStat) NewFolder.Name = key for key,v in next, val do if key == 'ForceStop' then local NewVal = Instance.new('BoolValue',NewFolder) NewVal.Name = key NewVal.Value = v else local NewVal = Instance.new('IntValue',NewFolder) NewVal.Name = key NewVal.Value = v end end else local NewVal = Instance.new('IntValue',NewStat) NewVal.Name = key NewVal.Value = val end end end end
SaveStats = function(Player) local UserId = Player.UserId local Stats = Player:WaitForChild('Stats') for i,val in next, Stats:GetChildren() do if val:IsA('Folder') then for i,v in next, val:GetChildren() do PlayerStats[UserId][Stats.Name][val.Name][v.Name] = v.Value end else PlayerStats[UserId][Stats.Name][val.Name] = val.Value end end for i,v in next, PlayerStats[UserId] do for j,k in next, v do if type(k) == 'table' then for key,val in next, k do end else end end end end
DataHandler.LoadData = function(Player) local UserId = Player.UserId local Data pcall(function() Data = PlayerData:GetAsync(UserId) end) if Data then PlayerStats[UserId] = Data else local s,e = pcall(function() PlayerData:SetAsync(UserId,DefaultStats) end) if not s then warn(e) end PlayerStats[UserId] = DefaultStats end LoadStats(Player) end
DataHandler.SaveData = function(Player) local UserId = Player.UserId SaveStats(Player) local s,e = pcall(function() PlayerData:SetAsync(UserId,PlayerStats[UserId]) end) if not s then warn(e) end end return DataHandler |
|
|
| Report Abuse |
|