Datastore not working

  1. What do you want to achieve? I want to make a datastore that can store multiple values. Right now, it is not storing anything.

  2. What is the issue? It’s not storing data at all.

  3. What solutions have you tried so far? I tried doing different things, like setting value of data as a table, using different keys, and comparing my datastore with other people’s. It still doesn’t function properly.

Here’s the code:

local currencyDS = DSS:GetDataStore("currencyDS")

game.Players.PlayerAdded:Connect(function(plr)
	
	local currency = Instance.new("Folder")
	currency.Name = "Currency"
	currency.Parent = plr
	
	local cash = Instance.new("IntValue")
	cash.Name = "Cash"
	cash.Parent = currency
	
	local playerUID = "player_" .. plr.UserId
	
	local data = {}
	
	local success, err = pcall(function()
		data = currencyDS:GetAsync(playerUID)
	end)
	if success then
		print("Success")
		if data then
			print("data collected")
			
			
			cash.Value = data[1]
			
		else
			cash.Value = 0
		end
	else
		warn(err)
	end
end)

game.Players.PlayerRemoving:Connect(function(plr)
	local currency = plr.Currency
	local cash = currency.Cash

	local data = {
		cash.Value
	}
	
	local playerUID = "player_" .. plr.UserId
	
	local success, err = pcall(function()
		currencyDS:SetAsync(playerUID)
	end)

	if success then
		print("data saved")
	else
		warn(err)
	end


end)

You arent giving the DataStore anything to save, you only put the first argument inside SetAsync, and not the second argument, The Second Argument is the item that its going to save.

4 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.