Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

When I use a command to change a Money value it does not save?

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

0

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...

0

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.

2 answers

✓ Accepted answer

It's probably HD Admin changing the money client-side.

The client does not replicate to the server, meaning the server cannot see what the client sees.

In studio, playtest your game. In the topbar of home it should say Client with a blue computer-like icon. Click that and it should change a bit, switching to the server with a green icon. Now in studio find the money value of the player. Change the value to whatever and leave playtest. If the value does not save it might be your script isn't working.

Yeah I'm stupid. I made it a client command which only affects the client. To fix this I just went into the Commands script and wrote there like this:

-- << RETRIEVE FRAMEWORK >>
local main = _G.HDAdminMain
local settings = main.settings



-- << COMMANDS >>
local module = {
	
	-----------------------------------
	{
	Name = "setmoney";
	Aliases	= {"sm"};
	Prefixes = {settings.Prefix};
	Rank = 3;
	RankLock = false;
	Loopable = false;
	Tags = {};
	Description = "Will set the money of the player to the amount you specify.";
	Contributors = {"FerWasTaken"};
	--
	Args = {"Player","Value"};
	ClientCommand = false;
	FireAllClients = true;
	Function = function(speaker, args)
		local plr = tostring(args[1])
		local value = args[2]
		game.Players[plr].leaderstats.Money.Value = value
	end;
	--
	};
	-----------------------------------
	{
	Name = "givemoney";
	Aliases	= {"gm"};
	Prefixes = {settings.Prefix};
	Rank = 3;
	RankLock = false;
	Loopable = false;
	Tags = {};
	Description = "Will add the amount of money you specified to the player.";
	Contributors = {"FerWasTaken"};
	--
	Args = {"Player","Value"};
	ClientCommand = false;
	FireAllClients = true;
	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;
	--
	};
	-----------------------------------
	{
	Name = "takemoney";
	Aliases	= {"tm"};
	Prefixes = {settings.Prefix};
	Rank = 3;
	RankLock = false;
	Loopable = false;
	Tags = {};
	Description = "Will subtract the amount of money you specified to the player.";
	Contributors = {"FerWasTaken"};
	--
	Args = {"Player","Value"};
	ClientCommand = false;
	FireAllClients = true;
	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;
	--
	};
	-----------------------------------
	{
	Name = "";
	Aliases	= {};
	Prefixes = {settings.Prefix};
	Rank = 1;
	RankLock = false;
	Loopable = false;
	Tags = {};
	Description = "";
	Contributors = {};
	--
	Args = {};
	--[[
	ClientCommand = true;
	FireAllClients = true;
	BlockWhenPunished = true;
	PreFunction = function(speaker, args)
		
	end;
	Function = function(speaker, args)
		wait(1)
	end;
	--]]
	--
	};
	
	
	
	
	-----------------------------------
	
};



return module

Thanks for helping me with this very dumb mistake.

This discussion is preserved as it was. New answers, comments, and votes are closed.