Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 3 years ago
Edited 3 years ago

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)
0
Is this in the StarterGui? Dec_ade 47 — 3y
0
Yes, it is. Should i put it somewhere else? Sorry I'm still trying to learn this ItsJZaid 45 — 3y
0
Okay yeah, I just tried using serverscriptstorage and it prints line 08. ItsJZaid 45 — 3y

2 answers

Log in to vote
2
Answered by
uhi_o 417 Moderation Voter
3 years ago
Edited 3 years ago

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.

0
Upvoted. raid6n 2196 — 3y
Ad
Log in to vote
1
Answered by
raid6n 2196 Moderation Voter Community Moderator
3 years ago
Edited 3 years ago

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

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

Answer this question