How to change text if player has a badge

im making a gasa4 like game and I want to display which ending the player has with badges

I have a ui that has all the endings in boxes and the text in each box is ??? until you get the badge then it turn to the name of the ending

heres a code that I have but the problem is that it changes the text even if the player doesnt have the badge

local BadgeService = game:GetService("BadgeService")

local BadgeId = 2130284698

local function checkBadge(player, BadgeId)
	
	local succes, badge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId)
	end)
	
	return badge
end

script.Parent.Text = "Capybara"

2 Likes

Maybe try:

local BadgeService = game:GetService("BadgeService")

while true do
wait()
if BadgeService:UserHasBadgeAsync(UserId, BadgeId) then
    script.Parent.Text = "Text"
else
    script.Parent.Text = "Othertext"
end
end
1 Like
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2130284698

while true do
wait(0.5)
if BadgeService:UserHasBadgeAsync(player, BadgeId) then
    script.Parent.Text = "Capybara"
else
    script.Parent.Text = "Change to text if doesn't have badge"
end
end

This should work

1 Like

ill try this now

There was a mistake, update the page and try it again

this is pretty simalar to the first one but it deffines the BadgeId

it doesnt deffine the user id though?

The user id doesn’t need defined

1 Like

Refresh the page. Try it now. It should work

hmm well it doesnt seem to be working
and the userid is underlined in red

Oh, I see…I’ll tell you when I get it working

1 Like

Alright try it now…I belive player does not need defined. If not you might just have to make a variable for the player, off the top of my head I dont know what that would be

1 Like

hmmm still doesnt work
i didnt get any errors either

Does it work? I think maybe you should add a variable like

local Player = game:GetService("Players")

This probably wont work, I actually dont understand the Players service real well

i did this still doesnt work though
ima try it not in studio

local BadgeService = game:GetService("BadgeService")
local BadgeId = 2130284698

local Player = game:GetService("Players")

while true do
	wait(0.5)
	if BadgeService:UserHasBadgeAsync(Player, BadgeId) then
		script.Parent.Text = "Capybara"
	else
		script.Parent.Text = "???"
	end
end

I’ll try some stuff out in studio…I’m not in studio. Sorry for all the problems

1 Like

use lowercase player where it says (Player, BadgeId). It wont work if you use uppercase

1 Like

And remove the variable about Player

why wouldnt it work with uppercase since the variable for players is capital

local BadgeService = game:GetService("BadgeService")
local BadgeId = 2130284698

while true do
	wait()
	if BadgeService:UserHasBadgeAsync(player, BadgeId) then
		script.Parent.Text = "Capybara"
	else
		script.Parent.Text = "???"
	end
end

Use this…

1 Like

Yeah, I didnt know you added the variable