local DSS = game:GetService("DataStoreService")
local CoinStore = DSS:GetDataStore("CoinStore")

game.Players.PlayerAdded:Connect(function(Player)
	local PlayerFolder = Instance.new("Folder", Player)
	PlayerFolder.Name = "PlayerFolder"
	local Coins = Instance.new("IntValue", PlayerFolder)
	Coins.Name = "Coins"
	
	local CoinData
	
	
	local Success, ErrorMesesage = pcall(function()
	CoinData = CoinStore:GetAsync(Player.UserId.."-coins")
	end)
	if Success then
		Coins.Value = CoinData
	else
		warn("Did not load data.")
	end
	
end)

game.Players.PlayerRemoving:Connect(function(Player)
	
	local Success, Error = pcall(function()
		CoinStore:SetAsync(Player.UserId.."-coins", Player.PlayerFolder.Coins.Value)
	end)
	
	if Success then
		print("It was a success")
	else
		warn(Error)
		print("Not successful")
	end
	
end)

I'm just beginning to learn how to use data stores and looked at a few different ways people have done them and I can't see any problems with what I have. I really want to get better at understanding and using data stores. Does anyone see anything wrong that would prevent this from working at all?

When I test it, Nothing shows up in the output at all. Leading me to think that I have not set it up properly.

2 comments

0

Did you use a LocalScript or a server-sided Script?

0

I used a server-sided script. The parent of the script is ServerScriptService.