So, I made this out of what CodeTheorem gave me. When I say /save, it prints Saved. When I say /load, it prints loaded. But, when I load after saving, my cash gets set to 0 and doesn't continue to increase. After reading through the code, to me it seems like it's saving the names of the Values and not the actual values of them. When I load from the Data Store, I want it to set each Value to the value they were at when I saved.
local KEY_PREFIX = "userid_" local ds = game:GetService("DataStoreService"):GetDataStore("PlayerValuesDataStore") local profilesHolder = game.Workspace.Profiles Debounce = true function saveToDataStore(plr) if Debounce == true then Debounce = false local key = KEY_PREFIX .. tostring(plr.userId) local profile = profilesHolder[plr.Name] local value = {} for i,v in ipairs(profile:GetChildren()) do value[v.Name] = v.Value print(v.Name .. " = " .. tostring(v.Value)) end ds:SetAsync(key, value) wait(15) print("Saved") Debounce = true elseif Debounce == false then print("Not ready") end end function loadFromDataStore(plr) if Debounce == true then Debounce = false local key = KEY_PREFIX .. tostring(plr.userId) local data = ds:GetAsync(key) local profile = profilesHolder[plr.Name] local profileItems = profile:GetChildren() for i,v in ipairs(data) do profileItems[i].Value = v print(i .. " = " .. tostring(v)) end wait(15) print("Loaded") Debounce = true elseif Debounce == false then print("Not ready") end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) msg = msg:lower() if msg == "/save" then saveToDataStore(player) elseif msg == "/load" then loadFromDataStore(player) end end) end)
And here's the script that creates the values.
game.Players.PlayerAdded:connect(function(player) Profile = Instance.new("Model") Profile.Parent = script.Parent Profile.Name = (player.Name) Cash = Instance.new("NumberValue") Cash.Parent = script.Parent[player.Name] Cash.Name = "Cash" Cash.Value = 0 a = Cash:Clone() a.Name = "WaitTime" a.Parent = script.Parent[player.Name] a.Value = 5 a = Cash:Clone() a.Name = "Block1" a.Parent = script.Parent[player.Name] a = Cash:Clone() a.Name = "Block2" a.Parent = script.Parent[player.Name] end)
I'm sorry - I was really tired when I tried to help you last night and I had one small error in my code. I do sincerely apologize. The below code will work.
local KEY_PREFIX = "userid_" local ds = game:GetService("DataStoreService"):GetDataStore("PlayerValuesDataStore") local profilesHolder = game.Workspace.Profiles function saveToDataStore(plr) local key = KEY_PREFIX .. tostring(plr.userId) local profile = profilesHolder[plr.Name] local value = {} for i,v in ipairs(profile:GetChildren()) do value[v.Name] = v.Value print(v.Name .. " = " .. tostring(v.Value)) end ds:SetAsync(key, value) end function loadFromDataStore(plr) local key = KEY_PREFIX .. tostring(plr.userId) local data = ds:GetAsync(key) local profile = profilesHolder[plr.Name] local profileItems = profile:GetChildren() for i,v in ipairs(data) do profileItems[i].Value = v print(i .. " = " .. tostring(v)) end end game.Players.PlayerAdded:connect(function(player) player.Chatted:connect(function(msg) msg = msg:lower() if msg == "/save" then saveToDataStore(player) print("Saved") elseif msg == "/load" then loadFromDataStore(player) print("Loaded") end end) end)
I dont know if this will work but use the ":SaveNumber()" method here is the link
http://wiki.roblox.com/index.php?title=SaveNumber_(Method)
here is to load the ":LoadNumber()" method
http://wiki.roblox.com/index.php?title=LoadNumber_(Method)