#Badge list code for a find the game?

1 messages · Page 1 of 1 (latest)

tawdry sky
#

im unsure how to script so does anyone have a script for my find the game badge list?

ionic kettle
tawdry sky
#

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.

ionic kettle
tawdry sky
#

the original text is "not found" then when you have the badge the index should say "found"

ionic kettle
#

Oh so you wanna check if a player has a badge or not, if they have say "found" and if not say "not found"?

stark baneBOT
#

studio** You are now Level 2! **studio

tawdry sky
#

yeah

#

this is the gui so far

ionic kettle
#

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

ionic kettle
# tawdry sky this is the gui so far

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()`

tawdry sky
#

thanks

stark baneBOT
#

studio** You are now Level 1! **studio

tawdry sky
#

local script im guesing?

ionic kettle
#

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)

ionic kettle
tawdry sky
#

ok

#

thanks

ionic kettle
#

Are you new to coding?

tawdry sky
#

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?

ionic kettle
#

`-- 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

ionic kettle
tawdry sky
#

is there a difference if the text label isnt called texxt label?

ionic kettle
#

Can you send ss of where you're putting the script?

tawdry sky
ionic kettle
#

Did you change this ?
local BADGE_ID = 0 -- YOUR BADGE ID

#

If you leave it 0 it won't check anything

tawdry sky
#

yeah i did

ionic kettle
# tawdry sky yeah i did

Are you checking in studio maybe?
You will automatically have all the badges in your experience as you are the owner.

tawdry sky
#

yeah im checking in rbx studio

ionic kettle
tawdry sky
#

ohhh

ionic kettle
#

Try playtesting in game

tawdry sky
#

ok

#

i just updated it

#

sadly still no

#

although i am the owner some of the badges i dont even have lol

vocal cloak
#

LET PEOPLE LEARNNNNN