The datastore constantly prints “first” when I join the game regardless of it not being my first time playing the game - Studio access to api is on. No errors too
local dis = game:GetService("DataStoreService")
local rs = game:GetService("ReplicatedStorage")
local players = game:GetService("Players")
local cafe_datastore = dis:GetDataStore("CafeDatastore")
local function saveData(player)
local cafe_table = {
["Currency"] = {
["Coins"] = player.Currency.Coins.Value;
};
}
print(player.Currency.Coins.Value)
local success, errormessage = pcall(function()
cafe_datastore:UpdateAsync(player.UserId, cafe_table)
end)
end
local function loadData(player)
local currency = Instance.new("Folder")
currency.Name = "Currency"
currency.Parent = player
local coins = Instance.new("IntValue")
coins.Name = "Coins"
coins.Parent = currency
local cafe_table
local success, errormessage = pcall(function()
cafe_table = cafe_datastore:GetAsync(player.UserId)
end)
if cafe_table then
coins.Value = cafe_table.Currency["Coins"]
else
print("first")
coins.Value = 0
end
end
game.Players.PlayerAdded:Connect(loadData)
game.Players.PlayerRemoving:Connect(saveData)
game:BindToClose(function()
for _, player in pairs(game.Players:GetPlayers()) do
saveData(player)
end
end)