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

If a gave money from the console it saved. But if the money is came from a tool not saving?

I am making a Simulator game but i just make a Datastore and publish the game. Then i tried to give my self a 100000 of money from the console i quit then i joined again, it saved. Then i try to make my Money to 0 again and click the tool for money. I quit then i joined its not saving. Why?

CODE:

BitcoinData = game:GetService("DataStoreService"):GetDataStore("BitcoinData")
MoneyData = game:GetService("DataStoreService"):GetDataStore("MoneyData")

game.Players.PlayerAdded:Connect(function(plr)
	local LB = Instance.new("Folder", plr)
	LB.Name = "leaderstats"
	
	local p = Instance.new("IntValue", LB)
	p.Name = "Bitcoin"
	p.Value = BitcoinData:GetAsync(plr.UserId)
	
	local r = Instance.new("IntValue", LB)
	r.Name = "Money"
	r.Value = MoneyData:GetAsync(plr.UserId)
	
	local bitcoinData, moneyData
	
	local success, errormessage = pcall(function()
		bitcoinData = BitcoinData:GetAsync("Bitcoin-"..plr.UserId)
		moneyData = MoneyData:GetAsync("Money-"..plr.UserId)
	end)
	
	if success then
		if bitcoinData then
			p.Value = bitcoinData
			r.Value = moneyData
		end
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local success, errormessage = pcall(function()
		BitcoinData:SetAsync("Bitcoin-"..plr.UserId,plr.leaderstats.Bitcoin.Value)
		MoneyData:SetAsync("Money-"..plr.UserId,plr.leaderstats.Money.Value)
	end)
end)

1 answer

✓ Accepted answer

Make sure that this "Tool" increase the value of "Money" on the server side

if you are doing it using a localscript, it will increase the "money" locally, but the server version of "money" will still be the same

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