Need help with shop/currency datasave

You can’t store a table value inside a DataStore, just a warning.

Oh really I honestly never knew that. I always use ProfileService or Datastore2. My bad.

What?

You can save a table consisting of player data inside data stores.

You can’t pass a table value as the 2nd value to SetAsync/UpdateAsync. To achieve storing multiple data from a table value you’d have to table.concat() the table first with a suitable delimiter and then store the string value returned by the call to table.concat() in the DataStore.

Yes, you can actually save tables inside a DataStore:

Code used for testing:

local DataStoreService = game:GetService("DataStoreService")
local DataStore = DataStoreService:GetDataStore("PlayerData")

local Template = {
	["Money"] = 0;
	["Inventory"] = {};
	["ClaimedCodes"] = {};
}

game:GetService("Players").PlayerAdded:Connect(function(Player)
	local PlayerData = DataStore:GetAsync(Player.UserId.."Data")
	
	if PlayerData == nil then
		DataStore:SetAsync(Player.UserId.."Data", Template)
		warn(Player.Name.." Have no data, added the data template")
	end
	
	print(DataStore:GetAsync(Player.UserId.."Data"))
end)
1 Like

I know why. I had this issue before. The buying is on the client. But the data store is in the server. And because of filtering enabled the clients new cash wont be sent to the server.So the old cash would be on the server and would save to that. This can be fixed using remote events Bindable Events and Functions | Roblox Creator Documentation

So I just make a button with a script to fire off a remote event that fires off a script in server script services like some pople have said already but I did not quite understand? Is that all I need to do?

(i know how to like basic script but ive never rlly used events)

Make a remote event in rep storage. Then make the button check if the player has enough cash when its clicked, using the mouse.buttom1click function. If the guy has enough then fire the remote event. Ctrl x all the buying stuff and subtracting curency on the server. Add a NORMAL script into server script service. Do ctrl v to insert the buying stuff in the server script. Boom done

1: Make sure you are changing the value of the money from the server and not from the client.

2: If you are sure that you are changing the value of money from the server, I recommend adding a print to your code to see if the script is really detecting the change of the value:

local datastore = game:GetService("DataStoreService")
local ds1 = datastore:GetDataStore("MoneySaveSystem")

game.Players.PlayerAdded:connect(function(plr)
	local folder = Instance.new("Folder", plr)
	folder.Name = "leaderstats"
	local money = Instance.new("IntValue", folder)
	money.Name = "Money"

	money.Value = ds1:GetAsync(plr.UserId) or 0
	ds1:SetAsync(plr.UserId, money.Value)

	money.Changed:connect(function()
        print("Money value changed")
		ds1:SetAsync(plr.UserId, money.Value)
	end)
end)

I hope i helped you to solve the problem, if so, be sure to mark my reply as a solution.

Happy coding!

Also I had the same issue like 2 days ago. And thats how i fixed it. Using remote events.

The problem is not with the data store. Its with the buying. Since the buyign is done in the client the server wont see the new value. Due to filtering enabled. In order to fix this u need to use remot eevnets

is there anyway you could right the first part of the sever script sercive script? i dont know how i would start that. This is the script that is currently inside of my Buy button

local item = script.Parent
local Shoes = script.Parent.Parent.Parent.Frame1.Shoes  
local value = 40000 

item.MouseButton1Click:Connect(function()
	if game.Players.LocalPlayer.leaderstats.Money.Value >= value then
		game.Players.LocalPlayer.leaderstats.Money.Value = game.Players.LocalPlayer.leaderstats.Money.Value - value
		item.Text = "purchased"
		Shoes.Visible = true
		value = 0
		
	else
		item.Text = "not purchased"
		wait(1)
		item.Text = "Purchase"
	
			value = 0
			Shoes.Visible = true
		end
		
	
end)


```and for the event to fire it would i just put 
```lua
Purchase:FireServer() --purcahse is the event name
game.ReplicatedStorage.RemoteEvent.OnServerEvent:Connect(function(Player) -- add everything you sent from the server AFTER PLAYER. Player is NEEDED for the script to work. If you dont have this the script will error. Also make remote event to the name of your remote event
	local Price = 20
	local Cash = Player.leaderstats.Cash -- change cash and leaderstats to what the currency is saved in
	Cash.Value -= Price
	--- add what the purchase does here.
end)

If you need anything then jusst tell me

If you want me to help you to the fullest extent then you can add me to a teamcreate and i’ll help you real time and I could understand the systems more

False, you CAN save tables in data stores, as stated from the API page itself.

1 Like

DataStore2, has a lot more functionality, yes. ProfileService as well.