i need to make badge which player gonna recieve when some of his friends joined him (friend also must get that badge)
Hi,
You can use the Players
service to check when a player joins the game. Once a player joins the game, you can loop through all the current players within the game and check if the player who joined the game is friends with any of those players via player:IsFriendsWith(userId)
.
You can then use the BadgeService
service to award any players who are friends. The code below is a simple way to achieve this effect:
-- services
local players = game:GetService("Players")
local badgeService = game:GetService("BadgeService")
-- variables
local BADGE_ID = 0000000
-- functions
local function awardBadge(player: Player)
local success, result = pcall(
function ()
if (badgeService:UserHasBadgeAsync(player.UserId, BADGE_ID)) then return end
return badgeService:AwardBadge(player.UserId, BADGE_ID)
end
)
end
local function playerAdded(player: Player)
for index, loopedPlayer in ipairs(players:GetPlayers()) do
if (loopedPlayer:IsFriendsWith(player.UserId)) then
awardBadge(loopedPlayer)
awardBadge(player)
end
end
end
players.PlayerAdded:Connect(playerAdded)
for index, player in ipairs(players:GetPlayers()) do
task.spawn(playerAdded, player)
end
2 Likes
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.