How can I “see” how much coins someone has without them being on?
game.Players.PlayerAdded:connect(function(player)
local leaderstats = Instance.new("Folder")
leaderstats.Name = "leaderstats"
local Coins = Instance.new("NumberValue")
Coins.Parent = leaderstats
Coins.Name = "Coins"
leaderstats.Parent = player
local save = dataStore:GetAsync(player.UserId.."_save")
if save ~= nil then
player.leaderstats.Coins.Value = save
end
end)
game.Players.PlayerRemoving:Connect(function(player)
local saving = player.leaderstats.Coins.Value
dataStore:SetAsync(player.UserId.."_save", saving)
end)
local UserId = game.Players:GetUserIdFromNameAsync("raid6n")
local key = (UserId.."_save")
print(dataStore:GetAsync(key)) -- prints nothing
No, that should still show up. If it prints nil then that means there is no data on the key whatsoever. This most likely means the data was never saved, make sure “studio access to api services” is enabled.
That seems reasonable. You could try and use BindToClose to save the data of all existing players once the server closes. This should also make sure that the server does not shutdown until the data has been saved.