Hello. I have a problem with SaveData.
I’ll warn you right away that I don’t really understand roblox studio, well, everyone starts somewhere.
The script does not work in one game, but it works fine in another (from which I took it). Can you help me fix it?
Roblox definitely does not find errors in it.
script:
local DSS = game:GetService(“DataStoreService”)
local dVersion = 1
local save = DSS:GetDataStore(“Stage” … dVersion)
game.Players.PlayerAdded:Connect(function(player)
local success, response = pcall(
save.GetAsync, save, player.UserId
)
if success then
local Stage
if response ~= nil then
Stage = response
else
Stage = 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 = Stage
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)
Please forgive me in advance if I have behaved stupidly somewhere.