Awarding a Badge Based on Player Joining

would like to create a script that awards a badge to players who join any server in my game except the one im currently in when my userId is 4092285006 is in any server. Im trying to award the badge (Badge id: 2151451557).

. I am trying to create a script that detects if the player with userId 4092285006(my user Id) is in a server other than the one a different player is in. I want to award that the badge only when another player joins a different server from mine.

I’ve tried several script variations to achieve this behavior, but none have the correct results. I have also looked at the Developer Hub for information but couldn’t find a solution.

Couldn’t you just check when a player joins then if your in the game it doesn’t award?

local UserId = 4092285006
local BadgeId = 2151451557

local BadgeService = game:GetService('BadgeService')

game.Players.PlayerAdded:Connect(function(player)

 local Name = game.Players:GetNameFromUserIdAsync(UserId)
 
 if game.Players[Name] then
  return
end

BadgeService:AwardBadge(player.UserId,BadgeId)

end)

In my game, the server size is set to 1, and I want to award the badge when a player is in a different server from the one im in

So you want a player to be awarded a badge if they join the game while your playing?

Exactly, award the badge when a player joins if im in any server

Hope this works haven’t tested it yet

local UserId = 4092285006
local BadgeId = 2151451557

local BadgeService = game:GetService('BadgeService')

game.Players.PlayerAdded:Connect(function(player)
 local Name = game.Players:GetNameFromUserIdAsync(UserId)
 if game.Players:FindFirstChild("Roblox") then--change roblox to ur username
BadgeService:AwardBadge(player.UserId,BadgeId)

end


end)
1 Like
local Players = game:GetService("Players")
local Teleport = game:GetService("TeleportService")
local Badges = game:GetService("BadgeService")
Players.PlayerAdded:Connect(function(player: Player)
	local success, errorfailed, placeid,jobid
	local yeah, FAIL = pcall(function()
		success, errorfailed, placeid, jobid =  Teleport:GetPlayerPlaceInstanceAsync(Players:GetUserIdFromNameAsync("AJjIsCOoLs"))
	end)
	if yeah then
		if placeid == game.PlaceId then
			xpcall(function(...) 
				Badges:AwardBadge(player.UserId,2151451557)
			end,function(a0) 
				print(tostring(a0))
			end)
		end
	end
end)
1 Like

Try this it uses messaging service for cross server communication:

local OwnerIsInGame  = false
local UserId = 4092285006
local BadgeId = 2151451557

local BadgeService = game:GetService('BadgeService')
local MessagingService = game:GetService('MessagingService')

MessagingService:SubscribeAsync("Owner",function(msg)
	OwnerIsInGame = msg.Data
end)

game.Players.PlayerAdded:Connect(function(player)

	local Name = game.Players:GetNameFromUserIdAsync(UserId)
	
	if player.UserId == UserId then
		MessagingService:PublishAsync("Owner",true)
	end
	
	
	if OwnerIsInGame then
		BadgeService:AwardBadge(player.UserId,BadgeId)
	end

	

end)

game.Players.PlayerRemoving:Connect(function(player)
	
	if player.UserId == UserId then
		MessagingService:PublishAsync("Owner",false)
		
	end
	
end)
1 Like