Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Display a note if user does not own badge, don't display it if they do?

Updated!!!!

I managed to fix the last issue with raid6n's suggestion. However I still have issues with this. My problem now is that when the user does not own badge the "note.Visible = true" doesn't make the note appear. Someone told me it's because the StarterGui... blah blah get moved somewhere else. That's all I remember, can someone help with that?

local note = game.StarterGui.MainGui.Note
local player = game:GetService("Players")
local badgeid = 2124518313
local BadgeService = game:GetService("BadgeService")

player.PlayerAdded:Connect(function(player)
	if BadgeService:UserHasBadgeAsync(player.UserId, badgeid) then
		print("User owns badge, do not display note.")
	else
		print("User does not own badge, display note.")
		note.Visible = true
	end
end)

3 comments

0

Is this in the StarterGui?

0

Yes, it is. Should i put it somewhere else? Sorry I'm still trying to learn this

0

Okay yeah, I just tried using serverscriptstorage and it prints line 08.

2 answers

✓ Accepted answer

Do if BadgeService:UserHasBadgeAsync(player.UserId, badgeid) then on line 7.

https://developer.roblox.com/en-us/api-reference/function/BadgeService/UserHasBadgeAsync

What raid6n said is correct, but you would need a constant check if the user earned the badge. You would need to put that in a while loop.

local player = game:GetService("Players")
local badgeid = 2124518313
local BadgeService = game:GetService("BadgeService")

player.PlayerAdded:Connect(function(player)
    while true do
        wait(10) --10 seems fair enough
        if BadgeService:UserHasBadgeAsync(player.UserId, badgeid) then
            print("User owns badge, do not display note.")
        else
            print("User does not own badge, display note.")
            player.PlayerGui.MainGui.Note.Visible = true
        end
    end
end)

Or you can always do a check when you give the badge to the user to avoid while loops.

Since there is always another way than using while loops.

1 comment

0

Upvoted.

This discussion is preserved as it was. New answers, comments, and votes are closed.