Because at least it used to work without problems and I’m sure nothing has changed in it, especially since I even rewrote it, but nothing has changed at all
local dVersion = 1
local save = DSS:GetDataStore(“Coins”…dVersion)
game.Players.PlayerAdded:Connect(function(player)
local PD = save:GetAsync(player.UserId)
local coins
if PD ~= nil then
coins = PD
else
coins = 0
save:SetAsync(player.UserId,0)
end
local coinsValue = Instance,new("NumberValue", player)
coinsValue.Name = "Currency"
coinsValue.Value = coins
end)
game:BindToClose(function()
print (“STOPPED!”)
for i,player in pairs(game.Players:GetPlayer()) do
local value = player.Currency.Value
save:SetAsync(player.UserId, value)
print("saved data for "..player.Name)
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local value = player.Currency.Value
if value ~= nil then
print(“Found data to save for “…player.Name…”!”)
save:SetAsync(player.UserId, value)
print("saved data for "…player.Name)
else
print(“Did not manage to ind data to save for “…player.Name…”!”)
end
end)
Firstly, you aren’t changing the Currency value from the client, correct? If you are doing so, it won’t replicate to the server, thus causing the data to not save correctly.
Secondly, I noticed numerous errors within your script, which when I corrected, the script worked perfectly fine in Studio.
Here’s the corrected script:
local DSS = game:GetService("DataStoreService")
local dVersion = 1
local save = DSS:GetDataStore("Coins" .. dVersion)
game.Players.PlayerAdded:Connect(function(player)
local success, response = pcall(
save.GetAsync, save, player.UserId
)
if success then
local coins
if response ~= nil then
coins = response
else
coins = 0
local success, response = pcall(
save.SetAsync, save, player.UserId, 0
)
if not success then
warn(response)
end
end
local coinsValue = Instance.new("NumberValue")
coinsValue.Name = "Currency"
coinsValue.Value = coins
coinsValue.Parent = player
else
warn(response)
end
end)
game:BindToClose(function()
print("STOPPED!")
for _, player in pairs(game.Players:GetPlayers()) do
local value = player.Currency.Value
local success, response = pcall(
save.SetAsync, save, player.UserId, value
)
if success then
print("Saved data for " .. player.Name)
else
warn(response)
end
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local value = player.Currency.Value
print(value)
if value ~= nil then
print("Found data to save for " .. player.Name .. "!")
local success, response = pcall(
save.SetAsync, save, player.UserId, value
)
if success then
print("Saved data for " .. player.Name)
else
warn(response)
end
else
print("Did not manage to find data to save for " .. player.Name .. "!")
end
end)