How would my Datastore save if I update the balance from the client?

Hey there!

So I was making a DataStore called Money. I have created a little ‘test’ script that removes the balance from the player and gives the object requested. However, when I leave, it does not save! I believe it is because I need to use a RemoteEvent, but I’m not quite sure.

Here is my DataStore script:

local DSS = game:GetService('DataStoreService')
local DS = DSS:GetDataStore('MoneyStats')

	local leaderstats ='Folder')
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = Player
	local money ='IntValue')
	money.Name = "Money"
	money.Parent = leaderstats
	money.Value = 0
	local data = DS:GetAsync(Player.UserId)
	if data then
		money.Value = data

	DS:SetAsync(Player.UserId, Player.leaderstats.Money.Value)

And here is my test script (ignore all the sofa variables):

-- // Buttons

local buyblacksofa = script.Parent.BlackBuyButton
local buybluesofa = script.Parent.BlueBuyButton
local buygreensofa = script.Parent.GreenBuyButton
local buyorangesofa = script.Parent.OrangeBuyButton
local buyredsofa = script.Parent.RedBuyButton
local buyyellowsofa = script.Parent.YellowBuyButton
local player = game.Players.LocalPlayer

local buywhitesofa = script.Parent.WhiteBuyButton
local frame = script.Parent.Parent.Frame
local purchasefailed = script.Parent.Parent.PurchaseFailed
local purchasegranted = script.Parent.Parent.PurchaseGranted

-- // Assets
local blacksofa = game.ReplicatedStorage.Sofa.BlackSofa
local bluesofa = game.ReplicatedStorage.Sofa.BlueSofa
local greensofa = game.ReplicatedStorage.Sofa.GreenSofa
local orangesofa = game.ReplicatedStorage.Sofa.OrangeSofa
local redsofa = game.ReplicatedStorage.Sofa.RedSofa
local yellowsofa = game.ReplicatedStorage.Sofa.YellowSofa
local whitesofa = game.ReplicatedStorage.Sofa.WhiteSofa

-- // The main script

	if player.leaderstats.Money.Value <= 500 then
		purchasefailed.Visible = true
		purchasefailed.Visible = false
		player.leaderstats.Money.Value >= 500 then
		player.leaderstats.Money.Value = player.leaderstats.Money.Value -500
			blacksofa.Parent = game.Workspace
		blacksofa.Position =, 0.5, -57)
		purchasegranted.Text = "Successfully purchased a Black Sofa!"
			purchasegranted.Visible = true
			purchasegranted.Visible = false

The DataStore script script is located inside ServerScriptService, and the test script is located inside my StarterGui (InsertTest.Frame).

Any help is very appreciated! I will be looking at every reply and try my hardest to follow your advice!

Thats not possible, its only possible if FilteringEnabled is turned to false but Roblox turned it to always true due to if the client can change Values and the Value will also be changed on ServerSide then the Client could exploit the game asily.

So what do I have to do? Use a server script and update it via a .PlayerAdded event?

Nothing will happen. If you’re using local scripts to update things, only the client can see it. The server just saves whatever data it created. So if the server made the players balance to 100 and on the client they increased it to 600, the server will still save 100 because the server can only see 100.

1 Like

Change the Values on ServerSide not on ClientSide.
also don’t forget what @VegetationBush Said

1 Like

Update the value on server using remote events

1 Like

You can update datastores from the client with RemoteEvents/Functions but using that method will create a huge vulnerability for exploiters.

1 Like