|
| 31 Jul 2015 12:28 AM |
I rewrote your code, it's a bit shorter but should be set up the same way you have it.
Try using this, tell me what comes up in the output, etc. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 12:28 AM |
local DataStore = game:GetService("DataStoreService"):GetDataStore("Customization")
local ListOfCustomizationTypes = { "Hair", "HairCol", "Face", "BColor", "Top", "Bottom" }
function SaveData(Player, Key, Value) DataStore:SetAsync(Player.userId.."_"..Key, Value) end
function LoadData(Player, Key) return DataStore:GetAsync(Player.userId.."_"..Key, Value) or nil end
function PlayerAdded(Player)
print("Loading Data for "..Player.Name)
local Stats = Instance.new("Folder",Player) Stats.Name = "Data"
local Customization = Instance.new("Folder",Player) Customization.Name = "Customization"
for _,CData in pairs(ListOfCustomizationTypes) do local Data = Instance.new("IntValue",Customization) Data.Name = CData Data.Value = LoadData(Player,CData) or 0 end
local Race = Instance.new("IntValue", Stats) Race.Name = "Race" Race.Value = LoadData(Player,"Race") or 0
local Level = Instance.new("IntValue", Stats) Level.Name = "Level" Level.Value = LoadData(Player, "Level") or 1
local EXP = Instance.new("IntValue", Level) EXP.Name = "EXP" EXP.Value = LoadData(Player,"EXP") or 0
local PLevel = Instance.new("IntValue",Stats) PLevel.Name = "PowerLevel" PLevel.Value = LoadData(Player,"PowerLevel") or 52613
EXP.Changed:connect(function() EXPChanged(Player, EXP, Level) PLevel.Value = Level.Value * 52613 end)
print("Data should be loaded for "..Player.Name) end
function PlayerRemoved(Player) print("Saving data for "..Player.Name)
local Stats = Player:FindFirstChild("Data") local Customization = Player:FindFirstChild("Customization")
if (Stats) and (Customization) then
for _,Data in pairs({"Race","Level","PowerLevel"}) do local GetData = Stats:FindFirstChild(Data) if GetData then SaveData(Player,Data,GetData.Value) end end
local GetData = Stats:FindFirstChild("Level"):FindFirstChild("EXP") if GetData then SaveData(Player,"EXP",GetData.Value) end
for _,CData in pairs(ListOfCustomizationTypes) do local GetData = Customization:FindFirstChild(CData) if GetData then SaveData(Player,CData,GetData.Value) end end end
print("Data should be saved for "..Player.Name) end
game.Players.PlayerAdded:connect(PlayerAdded) game.Players.PlayerRemoved:connect(PlayerRemoved) |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 12:29 AM |
Apologies, the very last line
"game.Players.PlayerRemoved:connect(PlayerRemoved)"
should be
Players.PlayerRemoving:
not
Players.PlayerRemoved: |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 12:45 AM |
@Developer thanks for your effort, but it still doesn't save :/ probably because of these errors
http://prntscr.com/7z46ie
http://prntscr.com/7z46jq
Could you fix them? Thanks |
|
|
| Report Abuse |
|
|
lsp425
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 603 |
|
|
| 31 Jul 2015 12:54 AM |
| Is DeveloperBlue noob? The question is was he ever not. |
|
|
| Report Abuse |
|
|
lsp425
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 603 |
|
|
| 31 Jul 2015 12:56 AM |
local DataStore = game:GetService("DataStoreService"):GetDataStore("Customization")
local ListOfCustomizationTypes = { "Hair", "HairCol", "Face", "BColor", "Top", "Bottom" }
function SaveData(Player, Key, Value) DataStore:SetAsync(Player.userId.."_"..Key, Value) end
function LoadData(Player, Key) return DataStore:GetAsync(Player.userId.."_"..Key) end
function PlayerAdded(Player)
print("Loading Data for "..Player.Name)
local Stats = Instance.new("Folder",Player) Stats.Name = "Data"
local Customization = Instance.new("Folder",Player) Customization.Name = "Customization"
for _,CData in pairs(ListOfCustomizationTypes) do local Data = Instance.new("IntValue",Customization) Data.Name = CData Data.Value = LoadData(Player,CData) or 0 end
local Race = Instance.new("IntValue", Stats) Race.Name = "Race" Race.Value = LoadData(Player,"Race") or 0
local Level = Instance.new("IntValue", Stats) Level.Name = "Level" Level.Value = LoadData(Player, "Level") or 1
local EXP = Instance.new("IntValue", Level) EXP.Name = "EXP" EXP.Value = LoadData(Player,"EXP") or 0
local PLevel = Instance.new("IntValue",Stats) PLevel.Name = "PowerLevel" PLevel.Value = LoadData(Player,"PowerLevel") or 52613
EXP.Changed:connect(function() EXPChanged(Player, EXP, Level) PLevel.Value = Level.Value * 52613 end)
print("Data should be loaded for "..Player.Name) end
function PlayerRemoved(Player) print("Saving data for "..Player.Name)
local Stats = Player:FindFirstChild("Data") local Customization = Player:FindFirstChild("Customization")
if (Stats) and (Customization) then
for _,Data in pairs({"Race","Level","PowerLevel"}) do local GetData = Stats:FindFirstChild(Data) if GetData then SaveData(Player,Data,GetData.Value) end end
local GetData = Stats:FindFirstChild("Level"):FindFirstChild("EXP") if GetData then SaveData(Player,"EXP",GetData.Value) end
for _,CData in pairs(ListOfCustomizationTypes) do local GetData = Customization:FindFirstChild(CData) if GetData then SaveData(Player,CData,GetData.Value) end end end
print("Data should be saved for "..Player.Name) end
game.Players.PlayerAdded:connect(PlayerAdded) game.Players.PlayerRemoving:connect(PlayerRemoved) |
|
|
| Report Abuse |
|
|
lsp425
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 603 |
|
|
| 31 Jul 2015 12:58 AM |
| You need to make the function EXPchanged at the top. Idk what blue wanted it to do. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 12:58 AM |
| @lsp http://prntscr.com/7z46ie is still there e.e |
|
|
| Report Abuse |
|
|
lsp425
|
  |
| Joined: 10 Dec 2011 |
| Total Posts: 603 |
|
| |
|
|
| 31 Jul 2015 01:05 AM |
| STILL doesn't save, omg datastore is so complicated, im so annoyed right now, I've been trying to fix for like 6 hours now...... |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 31 Jul 2015 01:12 AM |
That's a lot of characters. Would it help you if you could type
game.Players.PlayerRemoving:connect(function(player) m:setstat(player,'File1') end)
game.Players.PlayerAdded:connect(function(player) m:getstat(player,'File1') end)
, and do nothing else other than to create the value holding instances(other than ObjectValue) in the player when it enters? |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 01:26 AM |
| @Shung I don't understand? Could u like try fixing my script and what is setstat? I tried searching but got nothing |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 01:37 AM |
| Bump, I'll never get this fixed ;_; |
|
|
| Report Abuse |
|
|
| |
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 31 Jul 2015 02:01 AM |
I have a Module that enables you to save every value holding instance(eg: IntValue, NumberValue, BoolValue, etc...(other than ObjectValue)) found on the player(it doesn't have to be a child of the player, it can be a descendant at any generation) to the DataStore by calling a single function with two arguments
, and then load all of it from the DataStore, to the player (however you have it arranged), by calling another single function with two arguments.
All you have to do is put the instances on the player(however you normally arrange them) then it enters the game
Your script is very long, and combines Persistence and DataStore, and I really don't have time to scour through it for a potential problem, but I can offer an alternative solution. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 02:01 AM |
OMG SHUT UP
KILL THE DATA STORE
KILL KILL KILL |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 02:05 AM |
@Shung I'm actually using this script right now, but if you can't find a solution in this then please give me an alternative one, thanks
local DataStore = game:GetService("DataStoreService"):GetDataStore("Customisation")
local ListOfCustomisationTypes = { "Hair", "HairCol", "Face", "BColor", "Top", "Bottom" }
function SaveData(Player, Key, Value) DataStore:SetAsync(Player.userId.."_"..Key, Value) end
function LoadData(Player, Key) DataStore:GetAsync(Player.userId.."_"..Key) end
function PlayerAdded(Player)
print("Loading Data for "..Player.Name)
local Stats = Instance.new("Folder",Player) Stats.Name = "Data"
local Customisation = Instance.new("Folder",Player) Customisation.Name = "Customisation"
for _,CData in pairs(ListOfCustomisationTypes) do local Data = Instance.new("IntValue",Customisation) Data.Name = CData Data.Value = LoadData(Player,CData) or 0 end
local Race = Instance.new("IntValue", Stats) Race.Name = "Race" Race.Value = LoadData(Player,"Race") or 0
local Level = Instance.new("IntValue", Stats) Level.Name = "Level" Level.Value = LoadData(Player, "Level") or 1
local EXP = Instance.new("IntValue", Level) EXP.Name = "EXP" EXP.Value = LoadData(Player,"EXP") or 0
local PLevel = Instance.new("IntValue",Stats) PLevel.Name = "PowerLvl" PLevel.Value = LoadData(Player,"PowerLvl") or 52613
print("Data should be loaded for "..Player.Name) end
function PlayerRemoved(Player) print("Saving data for "..Player.Name)
local Stats = Player:FindFirstChild("Data") local Customisation = Player:FindFirstChild("Customisation")
if (Stats) and (Customisation) then
for _,Data in pairs({"Race","Level","PowerLvl"}) do local GetData = Stats:FindFirstChild(Data) if GetData then SaveData(Player,Data,GetData.Value) end end
local GetData = Stats:FindFirstChild("Level"):FindFirstChild("EXP") if GetData then SaveData(Player,"EXP",GetData.Value) end
for _,CData in pairs(ListOfCustomisationTypes) do local GetData = Customisation:FindFirstChild(CData) if GetData then SaveData(Player,CData,GetData.Value) end end end
print("Data should be saved for "..Player.Name) end
game.Players.PlayerAdded:connect(PlayerAdded) game.Players.PlayerRemoving:connect(PlayerRemoved) |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 31 Jul 2015 02:36 AM |
You're making a request for each value (which will get slow(problematic), when the DataStore throttles you back so you don't exceed the request/minute limit, if you have a lot of values to save,).
Other than that, without knowing what else you have going on(I imagine you haven't fully relinquished persistence since, by what I can see, you're still converting on that game), it looks like it should be working,..
,.. but
why are you not testing it as you go?!(You have prints outside of the action, on PlayerEntered and PlayerRemoving, but none inside telling you what it actually saved and loaded)
As for my alternative solution, at this point, I can't just give it away. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 03:03 AM |
What should I do then e.e
It prints that data was loaded and stuff, so I guess it doesn't save properly? As you said by looking at this script it looks like it should work... |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 31 Jul 2015 03:18 AM |
I've found that it can be relied on to save and load properly once I understood how to talk to it.
It is still possible that you have done everything right with regard to the DataStore, but have something else interfering with the values(or keys, or instances) after you load and/or before you save
, and, since you haven't done your due diligence when it comes to diagnostics(a print after every query, condition, and iteration if necessary), it will be hard for you to know what that interference or oversight is.
The single function solution is for sale. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 04:04 AM |
| So I've been trying to print something to see what the script loads, but I've failed ;_; could you please assist me |
|
|
| Report Abuse |
|
|
| |
|
|
| 31 Jul 2015 06:33 AM |
| pleaseeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee |
|
|
| Report Abuse |
|
|
ShungTzu
|
  |
| Joined: 14 Jun 2014 |
| Total Posts: 959 |
|
|
| 31 Jul 2015 12:09 PM |
EG:
function SaveData(Player, Key, Value) DataStore:SetAsync(Player.userId.."_"..Key, Value) print(player.Name..' '..key..' '..tostring(Value)) end
function LoadData(Player, Key) loaded=DataStore:GetAsync(Player.userId.."_"..Key) print(player.Name..' 'tostring(loaded)) end
function PlayerAdded(Player)
print("Loading Data for "..Player.Name)
local Stats = Instance.new("Folder",Player) Stats.Name = "Data"
local Customisation = Instance.new("Folder",Player) Customisation.Name = "Customisation"
for _,CData in pairs(ListOfCustomisationTypes) do local Data = Instance.new("IntValue",Customisation) Data.Name = CData Data.Value = LoadData(Player,CData) or 0 print(Data.Name..' '..tostring(Data.Value)) end
local Race = Instance.new("IntValue", Stats) Race.Name = "Race" Race.Value = LoadData(Player,"Race") or 0 print('Race '..tostring(Race.Value))
local Level = Instance.new("IntValue", Stats) Level.Name = "Level" Level.Value = LoadData(Player, "Level") or 1 --and so on... local EXP = Instance.new("IntValue", Level) EXP.Name = "EXP" EXP.Value = LoadData(Player,"EXP") or 0
local PLevel = Instance.new("IntValue",Stats) PLevel.Name = "PowerLvl" PLevel.Value = LoadData(Player,"PowerLvl") or 52613
print("Data should be loaded for "..Player.Name) end
Then Test, and look through the Output, and find what is not as you expected. |
|
|
| Report Abuse |
|
|
|
| 31 Jul 2015 12:56 PM |
Fixed,
For the first error, ", Value" just shouldn't be there, it's not an argument.
And for the second error, I simply forgot to write in your PxpChanged function.
Pastebin(dot)com/vjTztyaP |
|
|
| Report Abuse |
|
|