PcoWSkbVqDnWTu_dm2ix
We use cookies on this site to enhance your user experience

Badges for Meeting Creators

Badges for Meeting Creators

Jun 23 2018, 2:01 AM PST

Problem

You want to award people for meeting the creator of the game.

Solution

Use the AwardBadge method and the CreatorId property.

local creatorHere = function() 
	for _,v in ipairs(game.Players:GetPlayers()) do 
		if v.userId == game.CreatorId then 
			return true
		end
	end 
end 
 
game.Players.PlayerAdded:connect(function(pl)
        if pl.userId == game.CreatorId then
		for _,v in ipairs(game.Players:GetPlayers()) do 
			game:GetService('BadgeService'):AwardBadge(v.userId, 1234)
		end                 
	elseif creatorHere() then 
		game:GetService('BadgeService'):AwardBadge(pl.userId, 1234)
	end 
end)

Discussion

The creatorHere function will return true if one of the players in game is the creator. We then proceed to connect the PlayerAdded event and check if the newly added player is the creator. If so then we want to award the badge to any person already in the game. If the newly added player is not the creator of the game, then we check if the creator is there. If so, then they are awarded the badge.

Tags:
  • badge