Basically, I used HD Admin to create a few commands that change the leaderstat.Money.Value value. The commands work but when I leave the game, the changes made by the commands don't save but if I use the developer console to change the value it does save. How can I fix this?
Here is the ClientCommands script which I edited:
-- << RETRIEVE FRAMEWORK >>
local main = _G.HDAdminMain
-- << CLIENT COMMANDS >>
local module = {
----------------------------------------------------------------------
["setmoney"] = {
Function = function(speaker, args)
local plr = tostring(args[1])
local value = args[2]
game.Players[plr].leaderstats.Money.Value = value
end
};
----------------------------------------------------------------------
["givemoney"] = {
Function = function(speaker, args)
local plr = tostring(args[1])
local value = args[2]
local money = game.Players[plr].leaderstats.Money.Value
game.Players[plr].leaderstats.Money.Value = money + value
end;
};
----------------------------------------------------------------------
["takemoney"] = {
Function = function(speaker, args)
local plr = tostring(args[1])
local value = args[2]
local money = game.Players[plr].leaderstats.Money.Value
game.Players[plr].leaderstats.Money.Value = money - value
end;
};
----------------------------------------------------------------------
};
-- << SETUP >>
for commandName, command in pairs(module) do
command.Name = commandName
end
return module
And here is my DataStore script:
local DataStore = game:GetService("DataStoreService")
local myDataStore = DataStore:GetDataStore("myDataStore")
game.Players.PlayerAdded:Connect(function(plr)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
leaderstats.Parent = plr
local Money = Instance.new("NumberValue")
Money.Name = "Money"
Money.Parent = leaderstats
Money.Value = 0
local data
local success, errormessage = pcall(function()
data = myDataStore:GetAsync(plr.UserId.."-Money")
end)
if success then
Money.Value = data
else
print("There was an error while giving Player Data.")
warn(errormessage)
end
end)
game.Players.PlayerRemoving:Connect(function(plr)
local success, errormessage = pcall(function()
myDataStore:SetAsync(plr.UserId.."-Money", plr.leaderstats.Money.Value)
end)
if success then
print("Player Data successfully saved!")
else
print("There was an error while saving Player Data.")
warn(errormessage)
end
end)

2 comments
I made a script that gives you money over time and when I leave it doesn't save... It only saves if I use the console to adjust the value... I have no idea what the problem is...
I would like you to perform a series of test. First, go to test and start a 'local server' test. In that, use your admin commands to change the value of money. Then, go to Server page in Studio, and check the value of money. If the value doesn't change, bcz you are probably adjusting the value client side and not server side, also the datastores save the value that is saved on server side.