-
I would like to access datastores across games in asset manager the data store is for wins i want to add wins to a player from a game in asset manager then i go to the lobby i want it to save them for a leaderboard.
-
I don’t know how to access datastores across games in asset manager.
3. I have tried to script one for myself but i can’t do it.
This is the script if you want to edit it or make a new one. Thanks!
local DataStoreService = game:GetService(“DataStoreService”)
local Players = game:GetService(“Players”)
local winsDataStore = DataStoreService:GetDataStore(“WinsDataStore”)
local function savePlayerWins(player)
local userId = tostring(player.UserId)
local wins = player.leaderstats.Wins.Value
local success, errorMessage = pcall(function()
winsDataStore:SetAsync(userId, wins)
end)
if not success then
warn("Failed to save wins for player " .. player.Name .. ". Error: " .. errorMessage)
end
end
local function loadPlayerWins(player)
local userId = tostring(player.UserId)
local success, wins = pcall(function()
return winsDataStore:GetAsync(userId)
end)
if success then
player.leaderstats.Wins.Value = wins
else
player.leaderstats.Wins.Value = 0
warn("Failed to load wins for player " .. player.Name)
end
end
local function setupLeaderstats(player)
local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
leaderstats.Parent = player
local wins = Instance.new("IntValue")
wins.Name = "Wins"
wins.Value = 0
wins.Parent = leaderstats
loadPlayerWins(player)
end
Players.PlayerAdded:Connect(function(player)
setupLeaderstats(player)
player.OnDestroy:Connect(function()
savePlayerWins(player)
end)
end)
for _, player in ipairs(Players:GetPlayers()) do
setupLeaderstats(player)
player.OnDestroy:Connect(function()
savePlayerWins(player)
end)
end