|
| 31 May 2017 01:33 PM |
Hello, I've not been on ROBLOX for a while so actually I'm struggling to remember how this script I made worked -- I was never an expert of DataStores to begin with. It's currently not working, so I wonder if anyone could help shed some light on why it's not saving data. When I join the game my stats have gone.
StatsInfo = { {Name = 'Credits', Start = 0, Max = 90###########ype = 'DoubleConstrainedValue'}, {Name = 'Credits_onP', Start = 30, Max = 90###########ype = 'DoubleConstrainedValue'}, {Name = 'Bounty', Type = 'NumberValue'}, }
OwnedItems = {}
Data = game:GetService'DataStoreService':GetDataStore'PlayerData'
game.Players.ChildAdded:connect(function(p) local stats = Instance.new('Folder', p) stats.Name = 'PlayerValues' for _,v in pairs(StatsInfo) do local value = Instance.new(v.Type, stats) value.Name = v.Name if v.Max then value.MaxValue = v.Max end if v.Min then value.MinValue = v.Min end if v.Start then value.Value = v.Start end end local data = Data:GetAsync('Save_'..p.userId) if data then for i,v in pairs(data) do if stats:FindFirstChild(v.name) then stats[v.name].Value = v.value end end print(p.Name.."'s data has been loaded.") end --Now for owned items.. local items = Instance.new('Folder', p) items.Name = 'OwnedItems' local data2 = Data:GetAsync('SavedItems_'..p.userId) if data2 then for i,v in pairs(data2) do if game.Lighting:FindFirstChild(v.name) ~= nil and game.Lighting:FindFirstChild(v.name):IsA('StringValue') then local item = Instance.new('StringValue') item.Parent = items item.Name = v.name end end print(p.Name.."'s items have been loaded.") else print('Data Not Found') end --Done owned items. end)
game.Players.PlayerRemoving:connect(function(p) local ls = p:FindFirstChild'PlayerValues' if ls then local DataToSave = {} for i,v in pairs(ls:GetChildren()) do table.insert(DataToSave, {name = v.Name, value = v.Value}) end pcall(function() Data:SetAsync('Save_'..p.userId, DataToSave) print(p.Name.."'s data has been saved.") end) end --Now for items local si = p:FindFirstChild'OwnedItems' if si then local ItemsToSave = {} for i,v in pairs(si:GetChildren()) do table.insert(ItemsToSave, {name = v.Name, value = v.Value}) end pcall(function() Data:SetAsync('SavedItems_'..p.userId, ItemsToSave) print(p.Name.."'s items have been saved.") end) end end)
game.OnClose = function() wait(1) end
I really can't figure out why it is not working. Any help would be much appreciated. |
|
|
| Report Abuse |
|
|
| |
|
| |
|
JoshRBX
|
  |
| Joined: 19 May 2012 |
| Total Posts: 8778 |
|
|
| 01 Jun 2017 04:59 AM |
Check output, developer console and try to narrow down the problem tl;dr |
|
|
| Report Abuse |
|
|
OhSoMoody
|
  |
| Joined: 20 Dec 2015 |
| Total Posts: 139 |
|
|
| 01 Jun 2017 05:51 AM |
| That's a lot of script. Can you post again after doing the basic debugging please? Would love to help but need more clues of what goes wrong where. Suspicions...etc. |
|
|
| Report Abuse |
|
|
|
| 01 Jun 2017 06:46 AM |
Nothing prints except 'data not found'. -- but this is only for the Items bit.
Im really not very knowledgeable about data stores so I really don't know where to look. Could anyone maybe give me a rough skeleton to remake the script?
Much appreciated |
|
|
| Report Abuse |
|
|
OhSoMoody
|
  |
| Joined: 20 Dec 2015 |
| Total Posts: 139 |
|
|
| 02 Jun 2017 11:26 AM |
I think you should really try to study Data Stores in more detail...no amount of skeleton script is gonna help you otherwise.
Don't worry..it may look hard at first...but after a while you'll get the hang of it! Data Stores take easily a week to understand/try etc.
Also...remember you need to publish your game (every time you open it anew) for Data Stores to be able to talk to the servers. |
|
|
| Report Abuse |
|
|