Hey Everyone,
So for my story game, I’m adding wins from a different place that’s in the same game. I’ve heard this is possible but I’m not sure how to achieve it.
Here is the script I have in the lobby:
local Players = game:GetService('Players')
local DataStoreService = game:GetService('DataStoreService')
local WinsDataStore = DataStoreService:GetDataStore('Wins')
Players.PlayerAdded:Connect(function(Player)
local Stats = Instance.new('Folder')
Stats.Name = 'leaderstats'
Stats.Parent = Player
local Wins = Instance.new('IntValue')
Wins.Name = 'Wins'
Wins.Parent = Stats
local Data = WinsDataStore:GetAsync(Player.UserId)
if Data then
for name, value in pairs(Data.Stats) do
Stats[name].Value = value
end
end
end)
Players.PlayerRemoving:Connect(function(Player)
local SaveData = {Stats = {}}
for _, stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
WinsDataStore:SetAsync(Player.UserId,SaveData)
end)
game:BindToClose(function()
for _, Player in pairs(game.Players:GetPlayers()) do
local SaveData = {Stats = {}}
for _,stat in pairs(Player.leaderstats:GetChildren()) do
SaveData.Stats[stat.Name] = stat.Value
end
WinsDataStore:SetAsync(Player.UserId,SaveData)
end
wait(2)
end)
How can i add 1 win in a different place? I have no datastores in the other place.