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

Badges – Special Game Awards

Badges – Special Game Awards

Nov 16 2018, 12:32 PM PST 10 min

Badges allow you to create special awards for players who do something exceptional within your game — think of it like when your teacher gives you a gold star on a test for getting a perfect score. Badges are a great way to encourage players in your game, and many players will want to collect them all!

A badge might be awarded when a player:

  • Collects 100 gold stars in the game.
  • Jumps across a challenging series of platforms over a poison swamp.
  • Finds all 7 spirit keys to to unlock the kingdoms of Earth, Air, Lava, Ocean, Light, Shadow, and Dreams.

Creating a Badge

It costs R$ 100 to create a badge. To begin, open the Game Explorer window from the View tab in Roblox Studio.

In the window, right-click the Badges item and select Create Badge. This will open a new view with input fields for creating a badge.

Designing an Icon

Badges require an image of exactly 150×150 pixels. These steps will help you create an icon.

  1. Save the following template for a circular badge icon to your computer by right-clicking the image and selecting Save Image As….
  1. In an image editor or drawing application, fill in the blank circular area with some artwork.
  1. Save the badge image with a new file name (if you plan to create more than one badge for your game, you shouldn’t save over the original template file).

Uploading the Badge

The final step in the creation process is uploading the badge.

  1. Back in Roblox Studio, click the small button next to Find your image.
  1. Find the badge image on your computer and confirm that you’d like to upload it.
  2. Type in a name and description for the badge. Remember to tell players how to earn the badge so they have a specific goal to reach for!
  3. When you’re ready, click Preview. On the next screen, review the details for the badge and purchase when you’re ready. Once the purchase is complete, the badge will appear in the Badges tree of the Game Explorer window.

Scripting for Badges

To take full advantage of badges, you’ll need to use scripting. Here are some common examples:

Awarding a Badge

In the following script, the awardBadge() function can be called whenever it fits your game design, for instance when a player touches the final platform of a challenging jumping sequence. Using BadgeService functions, it checks if the player already owns the badge and, if not, awards it using BadgeService/AwardBadge|BadgeService:AwardBadge().

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
 
local badgeID = 0000000  -- Change this to your badge ID
 
local function awardBadge()
 
	local player = Players.LocalPlayer
	local hasBadge = false
 
	-- Check if the player already has the badge
	local success, message = pcall(function()
		hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
	end)
 
	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has badge: " .. tostring(message))
		return
	end
 
	if hasBadge == false then
		BadgeService:AwardBadge(player.UserId, badgeID)
	end
end

Checking Earned Badges

The following script waits for any player to enter the game and checks if they own a specific badge. This is useful, for example, in creating a locked door or teleporter that only works if a player owns a special badge.

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
 
local badgeID = 0000000  -- Change this to your badge ID
 
local function onPlayerAdded(player)
 
	local hasBadge = false
 
	-- Check if the player has the badge
	local success, message = pcall(function()
		hasBadge = BadgeService:UserHasBadgeAsync(player.UserId, badgeID)
	end)
 
	-- If there's an error, issue a warning and exit the function
	if not success then
		warn("Error while checking if player has badge: " .. tostring(message))
		return
	end
 
	if hasBadge == true then
		-- Assign this player a property/indicator that they own the badge
		--
	end
end
 
-- Connect 'PlayerAdded' events to the 'onPlayerAdded()' function
Players.PlayerAdded:Connect(onPlayerAdded)

Badges are a great way to inspire players to overcome specific challenges and encourage them to spend more time in your game. Hopefully this tutorial inspires you to add a variety of unique badges to your own games!

Tags:
  • badge
  • award