#Badge list code for a find the game?
1 messages · Page 1 of 1 (latest)
Do you want to find your game's badges? Or do you want to script badges?
i have badges made and obtainable already but i cant get the text to change when i have that specified badge, and i dont know how to script.
Can you specify which text change you mean? Is it a custom message or badge acquired message?
the original text is "not found" then when you have the badge the index should say "found"
Oh so you wanna check if a player has a badge or not, if they have say "found" and if not say "not found"?
** You are now Level 2! **
You can check badge id owned by player or not by using this
return BadgeService:UserHasBadgeAsync(player.UserId, BADGE_ID)"
use it inside a pcall and it will either return true or false
If true = found
if not = not found
Here's a quick script:
`local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local textLabel = script.Parent
local BADGE_ID = 0 -- YOUR BADGE ID
local function checkBadge()
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, BADGE_ID)
end)
if success then
if hasBadge then
textLabel.Text = "Found"
else
textLabel.Text = "Not Found"
end
end
end
checkBadge()`
thanks
** You are now Level 1! **
local script im guesing?
Oh also, if you want to instant update just add a function that updates text as soon as badge is awarded.
BadgeService.BadgeAwarded:Connect(function(userId, badgeId) if userId == player.UserId and badgeId == BADGE_ID then textLabel.Text = "Found" end end)
Inside UI
local textLabel = script.Parent
Inside your UI textlabel to be specific
Are you new to coding?
yeah started a few weeks ago still dont understand lol
i put it in the gui and i didnt see the changes when i tested
should look like this correct?
`-- NEEDED FOR ANY BADGE RELATED FUNCTION
local BadgeService = game:GetService("BadgeService")
-- NEEDED FOR GETTING PLAYERS IN GAME
local Players = game:GetService("Players")
local player = Players.LocalPlayer
-- WILL BE NEEDED TO CHANGE THE TEXTLABEL.TEXT AND CHANGE FOUND OR NOT FOUND
local textLabel = script.Parent
-- YOUR BADGE ID THAT YOU ARE CHECKING
local BADGE_ID = 0 -- YOUR BADGE ID
--THIS FUNCTION RUNS AS SOON AS GAME LOADS
local function checkBadge()
--PCALL PREVENTS SCRIPT FROM CRASHING
local success, hasBadge = pcall(function()
--CHECKS PLAYERS INVENTORY FOR THE BADGE ID YOU REPLACED THE LOCAL BADGD_ID WITH
return BadgeService:UserHasBadgeAsync(player.UserId, BADGE_ID)
--RETURN WILL RETURN A TRUE OR FALSE VALUE
end)
if success then
--IF RETURN IS TRUE
if hasBadge then
textLabel.Text = "Found"
else
-- IF RETURN IS FALSE
textLabel.Text = "Not Found"
end
end
end
--RUN THIS AS SOON AS SCRIPT STARTS
checkBadge()
--CHECK IF A USER JSUT EARNED A BADGE, IF IT'S SAME BADGE THAN MAKE TEXT TO FOUND
BadgeService.BadgeAwarded:Connect(function(userId, badgeId)
if userId == player.UserId and badgeId == BADGE_ID then
textLabel.Text = "Found"
end
end)`
Here's I explained with comments
Add the last function as well to check instant updates otherwise it will work when you rejoin
is there a difference if the text label isnt called texxt label?
no it takes the scripts parent, name shouldn't matter
Can you send ss of where you're putting the script?
Did you change this ?
local BADGE_ID = 0 -- YOUR BADGE ID
If you leave it 0 it won't check anything
yeah i did
Are you checking in studio maybe?
You will automatically have all the badges in your experience as you are the owner.
yeah im checking in rbx studio
Studio runs offline/locally, so it can't verify badge ownership
ohhh
Try playtesting in game
ok
i just updated it
sadly still no
although i am the owner some of the badges i dont even have lol
STOP SPOONDFEEDING, ITS AGAINST THE RULES
LET PEOPLE LEARNNNNN