How can I add wins to a player in a different place

Hey Developers!
I am very close to releasing my story game, I have just made a global leaderboard and top 3 statues.
I am on the part where I need to add the wins to the player.
I have the lobby and the main game which are in the same universe, because I need to use the Teleport to Private Server feature.

universe

In my main game, I need to send a message which will update the players wins adding one.
My datastore script is this:

local players = game:GetService('Players')
local dataStoreService = game:GetService('DataStoreService')

local saveDataStore = dataStoreService:GetDataStore('WinsForMuseum')

players.PlayerAdded:Connect(function(plr)
	
	local stats = Instance.new('Folder')
	stats.Name = 'leaderstats'
	stats.Parent = plr
	
	local Wins = Instance.new('IntValue')
	Wins.Name = 'Wins'
	Wins.Parent = stats
	
	local data = saveDataStore:GetAsync(plr.UserId)
	
	if data then
		
		for name, value in pairs(data.Stats) do
			
			stats[name].Value = value
		end
	end
	
	
	
end)

players.PlayerRemoving:Connect(function(plr)
	
	local saveData = {Stats = {}}
	
	for _,stat in pairs(plr.leaderstats:GetChildren()) do
		
		saveData.Stats[stat.Name] = stat.Value
			
	end
	
	saveDataStore:SetAsync(plr.UserId,saveData)
	
end)

game:BindToClose(function()
	
	for _,plr in pairs(players:GetChildren()) do
		
		local saveData = {Stats = {}}
		
		for _,stat in pairs(plr.leaderstats:GetChildren()) do
			
			saveData.Stats[stat.Name] = stat.Value
			
		end
		
		saveDataStore:SetAsync(plr.UserId, saveData)
		
	end
	
	wait(2)
	
end)

How can I add one win to every player in the game? There is no leaderstats in the main game, only in the lobby.

Help is appreciated!

4 Likes

You could use TeleportService:GetLocalPlayerTeleportData to transfer the data. In this case, you would want to transfer a boolean value that declares if player has won the game or not. And then back in the lobby you use that value to decide whether to add 1 to the “Win” stat or not.

2 Likes

@FlashFlame_Roblox method works, you also can implement DataStoreService. However, DatastoreService is an alternative, I’d say.

2 Likes

So I’ve got another issue now. Im doing this in the main game:

wait(5)
local TeleportData = {
	AddWins = true;
	PlayerName = Player.UserId;
			
			
	}
TeleportService:Teleport(4832886851, Player, TeleportData)

And in the lobby, I’m doing this:

local TeleportService = game:GetService("TeleportService")
 
local teleportData = TeleportService:GetLocalPlayerTeleportData()

if teleportData then
	local Player = game.Players:GetPlayerByUserId(teleportData.PlayerName)
	Player:WaitForChild('leaderstats'):WaitForChild('Wins').Value = Player.leaderstats.Wins.Value + 1
end

Nothing is happening, no errors.

2 Likes

In a table, we don’t use semi-colons, we use commas. And the last value don’t need a comma.

local TeleportData = {
	AddWins = true,
	PlayerName = Player.UserId		
}
2 Likes