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)

14 comments
When I save, it prints Saved. When I load it prints Loaded. It doesn't break the money gathering system anymore, but it doesn't load/save the data either. Is it a problem I created with my Chatted script? I could possibly not be gathering player correctly.
I've updated my script so that it will print the names of each item in the profile and their values on save and load. Mind replacing the script again and telling me what that looks like?
The problem is in the Loading. It saves and prints all the values, but when I load it prints Loaded but nothing else
Are you waiting at least 15 seconds in between the "/save" and "/load" commands? ROBLOX's DataStore caches every ten seconds, so you need to.
I will make it wait before trying, and then try again
It's still not working. I added the wait. And updated script can be found in the question. It doesn't print or load a list of values after loading. When I save it lists all the values however.
Are there any errors (red text)?
None at all
Well, we do have 15:40:38.156 - httpGet https://api.roblox.com/gametransactions/getpendingtransactions/?PlaceId=10965599&PlayerId=54680 failed. Trying again. Error: Forbidden. Elapsed time: 0.193088 15:40:38.157 - httpGet failed. Trying again. Elapsed time: 0.193088
No Red however
That httpGet has nothing to do with this. Okay...Can you give me a link to the game that this is at?
http://www.roblox.com/Testing-place?id=10965599
It's only printing to server console, not really sure how to get it to print to the local console.
I sent you a link on Twitter for a download of the place