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)
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.
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)