amaroxxdd
(MrAge)
December 29, 2022, 11:47pm
#1
Hello, as the title of this topic says, I would like to try how to make a text that says if the player has a bagde or not. I’ve been looking for this for a long time , but taking into account that several topics like this never end up with a solution. I would like this to have at least one
EX:
The player does not have the bagde
The player have the bagde
Screenshots are from this game: be a dad and get milk simulator [NEW BADGES] - Roblox
Vanniris
(Vanni)
December 30, 2022, 12:05am
#2
UserHasBadgeAsync method from BadgeService
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player, id)
end)
if not success then
return
end
if hasBadge then
-- whatever
end
note that UserHasBadgeAsync takes two Ids as argument: player and badge
amaroxxdd
(MrAge)
December 30, 2022, 12:24am
#3
And how would a textlabel show if the player has the bagde or not?
amaroxxdd
(MrAge)
December 30, 2022, 1:10am
#4
So basically if you don’t have the bagde the text puts you ‘‘bagde not achieved’’ and when you get it ‘‘bagde achieved’’
coolifysz
(coo1ify ok)
December 30, 2022, 1:15am
#5
local text = script.Parent
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player, id)
end)
if not success then
print("error")
end
if hasBadge then
text.Text = "achieved"
else
text.Text = "not achieved"
end
amaroxxdd
(MrAge)
December 30, 2022, 1:42am
#6
And would I have to put this inside the textlabel as a localscript?
coolifysz
(coo1ify ok)
December 30, 2022, 2:38am
#7
Yes.
bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb
amaroxxdd
(MrAge)
December 30, 2022, 2:47pm
#8
Hello, well, I tried what you put, but it gives me some errors and I don’t know what to do here…
Say unknow global
And it could also be done so that it is known what bagde you have or not, since it comes out that that is achivied without even having achieved it
With the last image I want to refer to the fact that I do not have the bagde
coolifysz
(coo1ify ok)
December 30, 2022, 6:41pm
#9
Add this,
local BadgeService = game:GetService("BadgeService")
local player = game.Players.LocalPlayer
local id = -- put your id here
amaroxxdd
(MrAge)
December 30, 2022, 7:41pm
#11
Well, it no longer gives me those errors, but it keeps showing me that I have the bagde achivied and I don’t have it…
coolifysz
(coo1ify ok)
December 30, 2022, 7:57pm
#12
May I see your code to see why it keeps doing that?
1 Like
mroaan
(NightCode)
December 30, 2022, 8:02pm
#13
You automatically own the badge that you create, so dont worry your script is working totally fine
coolifysz
(coo1ify ok)
December 30, 2022, 8:05pm
#14
His badge is probably deleted, by looking at his image he doesn’t own his badge.
amaroxxdd
(MrAge)
December 30, 2022, 8:07pm
#15
But if I delete it from my inventory, it should show "bagde not achieved’’, right? but it keeps saying i got it
amaroxxdd
(MrAge)
December 30, 2022, 8:08pm
#16
This is the code
local BadgeService = game:GetService(“BadgeService”)
local player = game.Players.LocalPlayer
local id = 2125782409
local text = script.Parent
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player, id)
end)
if not success then
print(“error”)
end
if hasBadge then
text.Text = “achieved”
else
text.Text = “not achieved”
end
coolifysz
(coo1ify ok)
December 30, 2022, 8:09pm
#17
You don’t own the badge correct?
amaroxxdd
(MrAge)
December 30, 2022, 8:09pm
#18
And no, it’s not deleted because I was able to get it, but even before I got it, it said that I had obtained it
coolifysz
(coo1ify ok)
December 30, 2022, 8:10pm
#19
Remove that, make your TextLabel say not achieved.
coolifysz
(coo1ify ok)
December 30, 2022, 8:12pm
#20
If it doesn’t work still, look at the documentation.
mroaan
(NightCode)
December 30, 2022, 8:12pm
#21
His badge is deleted? Wdym how is he able to use it in game then