spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 04:00 PM |
Why does this only save my level and nothing else:
local DataStore = ga#########################################################local PlayerData = game.ServerStorage:WaitForChild("Player Stats") game.Players.PlayerAdded:connect(function(Player) local Key = Player.UserId local Data = Instance.new('Folder') Data.Name = Player.Name Data.Parent = PlayerData local StoredData = Instance.new("Folder", Data) StoredData.Name = "DataStores" --[[>Level<]]-- local Level = Instance.new("NumberValue", StoredData) Level.Name = "Level" Level.Value = 1 --[[>Kills<]]-- local Kills = Instance.new("NumberValue", StoredData) Kills.Name = "Kills" Kills.Value = 0 --[[>KD<]]-- local KD = Instance.new("NumberValue", StoredData) KD.Name = "KD" KD.Value = 0 --[[>Deaths<]]-- local Deaths = Instance.new("NumberValue", StoredData) Deaths.Name = "Deaths" Deaths.Value = 0 --[[>Prestiges<]]-- local Prestige = Instance.new("NumberValue", StoredData) Prestige.Name = "Prestige" Prestige.Value = 0 --[[>XP<]]-- local XP = Instance.new("NumberValue", StoredData) XP.Name = "XP" XP.Value = 0 --[[>Total XP<]]-- local TotalXP = Instance.new("NumberValue", StoredData) TotalXP.Name = "TotalXP" TotalXP.Value = 0 --[[>Longest Killstreak<]]-- local LongestKillstreak = Instance.new("NumberValue", StoredData) LongestKillstreak.Name = "LongestKillstreak" LongestKillstreak.Value = 0 --[[>BanWarning1<]]-- local BanWarning1 = Instance.new("BoolValue", StoredData) BanWarning1.Name = "BanWarning1" BanWarning1.Value = false
--[[>BanWarning2<]]-- local BanWarning2 = Instance.new("BoolValue", StoredData) BanWarning2.Name = "BanWarning2" BanWarning2.Value = false
--[[>Banned<]]-- local Banned = Instance.new("BoolValue", StoredData) Banned.Name = "Banned" Banned.Value = false local Stats = DataStore:GetAsync(Key) if Stats then Level.Value = Stats[1] Prestige.Value = Stats[2] Kills.Value = Stats[3] Deaths.Value = Stats[4] XP.Value = Stats[5] TotalXP.Value = Stats[6] LongestKillstreak.Value = Stats[7] BanWarning1.Value = Stats[8] BanWarning2.Value = Stats[9] Banned.Value = Stats[10] else local StatsToSave = {Level.Value, Prestige.Value, XP.Value, Kills.Value. Deaths.Value, BanWarning1.Value, BanWarning2.Value, Banned.Value, TotalXP.Value, LongestKillstreak.Value} DataStore:SetAsync(Key, StatsToSave) end end)
game.Players.PlayerRemoving:connect(function(Player) local StatValues = PlayerData[Player.Name].DataStores local Key = Player.UserId local StatsToSave = {StatValues.Level.Value, StatValues.Prestige.Value, StatValues.XP.Value, StatValues.TotalXP.Value, StatValues.Kills.Value, StatValues.Deaths.Value, StatValues.BanWarning1.Value, StatValues.BanWarning2.Value,StatValues.Banned.Value, StatValues.LongestKillstreak.Value} DataStore:SetAsync(Key, StatsToSave) end)
|
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 04:03 PM |
| ########################################################################################################################### |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 04:03 PM |
I highly suggest looking at my code and learning from it. :)
https://www.roblox.com/library/438429848/DataStore-Leaderstats |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 04:05 PM |
Also for your ban warnings just use a string or number value and add to it each time. :P So you start at 0 then 1 then 2 then 3 perm banned. :P Or even better make it a string value and you can store length of ban and reason. :P |
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 04:07 PM |
Its a little bit difficult to read but the way you made it makes it hard to store my stuff because it locates it before having a way to locate the player. Also does this only apply with tools or do you get the children of a folder and save it?
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 04:10 PM |
| Actually my code is all very efficient. It's automatic all you do is add a new stat and it automatically saves it all no need to ever edit the saving and loading code. Just read the code and you'll see. |
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 05:33 PM |
I got yours to work i just revamped it a little. I still want to know what i did wrong with mine because id still like to learn. Im assuming that its only saving Level but since it doesnt save the other values properly, when it sets sync, only level is a saved value while the rest remain. How would i fix this.
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 05:35 PM |
I only looked at about the first ten lines and didn't ready anymore. xD
But yea give me a sec i'll read it. x) |
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 05:35 PM |
xD, it looks long cause made all my stats in the datastore script.
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 05:38 PM |
It's the way you're saving and loading the data.
You save the array like this: Level.Value, Prestige.Value, XP.Value, Kills.Value
Then load it like this: Level.Value = Stats[1] Prestige.Value = Stats[2] Kills.Value = Stats[3] Deaths.Value = Stats[4]
:P |
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 05:38 PM |
| ############################################################################### |
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 05:38 PM |
| As do I with my scripts but each stat only takes one line. ;) |
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 05:41 PM |
Thats what i though, i was loading the array wrong. Would i just use a loop instead with get children?
|
|
|
| Report Abuse |
|
|
DevVince
|
  |
| Joined: 08 Nov 2008 |
| Total Posts: 9245 |
|
|
| 13 Nov 2016 05:43 PM |
| See how my code loads and saves? Pretty much do it like that you never need to edit the save and loading functions. ;) Just add the new stat and edit it's props. |
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 05:50 PM |
So we save it the same way but not load it. Let me try loading it the way you do.
|
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
|
| 13 Nov 2016 05:56 PM |
like this?
if Stats then for i,v in pairs(Stats) do if v[2] then if StoredData:FindFirstChild(v.name) then StoredData[v.n].Value = v.v end else local StatsToSave = {Level.Value, Prestige.Value, XP.Value, Kills.Value. Deaths.Value, BanWarning1.Value, BanWarning2.Value, Banned.Value, TotalXP.Value, LongestKillstreak.Value} DataStore:SetAsync(Key, StatsToSave) end end end; end);
|
|
|
| Report Abuse |
|
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
| |
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
| |
|
spinywind
|
  |
| Joined: 26 Jan 2012 |
| Total Posts: 3580 |
|
| |
|