I've been trying to test out DataStore, but I keep getting this error. It refers to both the saving and the loading script. It works fine in-game (saving to a value, loading from it), but it doesn't save to the DataStore, so the stats don't remain for the next time it's played. I also got an output which said something about HTTP 404.
I looked over the lines output referred to, but I couldn't figure it out. Could someone help me find out what's wrong with it?
Also, is there a better way to save data to DataStore than saving when the player leaves? Preferably on a button's mouseclick?
The saving script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("PDS")
game.Players.PlayerRemoving:connect(function(player)
local key = "player_" ..player.userId
local valuesToSave = {player.leaderstats.Level.Value, player.GameInfo.Experience.Value, player.GameInfo.Coins.Value, player.GameInfo.Color.Value, player.GameInfo.SaveData.Value}
DataStore:SetAsync(key, valuesToSave)
end)
The loading script:
local DataStore = game:GetService("DataStoreService"):GetDataStore("PDS")
game.Players.PlayerAdded:connect(function(player)
repeat wait() until player.Character
local stats = Instance.new("IntValue", player)
stats.Name = "leaderstats"
local level = Instance.new("IntValue", stats)
level.Name = "Level"
local gameinfo = Instance.new("IntValue", player)
gameinfo.Name = "GameInfo"
local xp = Instance.new("NumberValue", gameinfo)
xp.Name = "Experience"
local coins = Instance.new("NumberValue", gameinfo)
coins.Name = "Coins"
local color = Instance.new("BrickColorValue", gameinfo)
color.Name = "Color"
local gamedata = Instance.new("BoolValue", gameinfo)
gamedata.Name = "SaveData"
local key = "player_" ..player.userId
local savedValues = DataStore:GetAsync(key)
if savedValues then
-- Save Format: {level, xp, coins, color, data}
level.Value = savedValues[1]
xp.Value = savedValues[2]
coins.Value = savedValues[3]
color.Value = savedValues[4]
gamedata.Value = savedValues[5]
else
local valuesToSave = {level.Value, xp.Value, coins.Value, color.Value, gamedata.Value}
DataStore:SetAsync(key, valuesToSave)
end
end)
Thanks in advance!
Note: I tested it in the actual place, not only Studio.

2 comments
local gui = p.PlayerGui.Save.Button gui.MouseButton1Down:connect(function() -- code end) ?
That's how to save on mouse click? Thanks.