How do i go about making coins gui save with data store

Hello, how do i make coins gui save with data stores

my script: and doesn’t seem to have any error in the output but still doesn’t work:

local label = script.Parent
local coins = workspace.Coins

local HttpService = game:GetService(“HttpService”)

local DataStoreService = game:GetService(“DataStoreService”)
local DataStore = DataStoreService:GetDataStore(“GameStore”)

local Players = game:GetService(“Players”)

local label = script.Parent

local coins = workspace.Coins

label.Text = “” … tostring(coins.Value)

coins:GetPropertyChangedSignal(“Value”):Connect(function()

print(“Change detected”)

label.Text = " " … tostring(coins.Value)

end)
Players.PlayerRemoving:connect(function(Player)
local Items = {
coins.Value,
}
Items = HttpService:JSONEncode(Items)
local Success, ErrorMessage = pcall(function()
DataStore:SetAsync(“user-”…tostring(Player.UserId), Items)
print(“changed!”)
label.Text = " " … tostring(coins.Value)
end)
if not Success then
warn("Failed to store data for user with id “…tostring(Player.UserId)…”. Error: "…ErrorMessage)
end
end)

why use JSON for this, I see no need for httpservice
also why not create a folder with values on player join, this would make saving data much easier

Please format the code. it will be easier to read.

:connect() is deprecated, use :Connect() also you don’t need to convert the data in JSON format because roblox already does it when you save it and when you load the data, it decodes it.

okay, i tried this

local label = script.Parent
local coins = workspace.Coins

label.Text = “” … tostring(coins.Value)

coins:GetPropertyChangedSignal(“Value”):Connect(function()
print(“Change detected”)
label.Text = " " … tostring(coins.Value)
local DataStore = game:GetService(“DataStoreService”):GetDataStore(“MyDStore”)-- You can change this anything you want

game.Players.PlayerAdded:Connect(function(player)
	local key = "key-"..player.userid
	coins.Name = "Coins" -- You can change this anything you want

	local save = DataStore:GetAsync(key)
	if save then
		coins.value = save[1]
	else
		local load = tostring(coins.Value)
		DataStore:SetAsync(key,load)
	end
end)

game.Players.PlayerRemoving:Connect(function(player)
	local key = "key-"..player.userid
	local load = tostring(coins.Value) -- Currency name here
	DataStore:SetAsync(key,load)
end)

end)