How Do I Make A Gui Appear To Only Players Who Own A Badge?

Hello Developers

How Do I Make A Gui Appear To Only Players Who Own A Badge ?

For Example When A User Gains A Badge How Do I Make A Ui Appear Only For Them In Game For Example A Halo Gui To Put On A Exclusive Badge Rewarded Halo In Game . Or A Secret Teleporter For Badge Owners Only

2 Likes

It is rather simple. To find only the players who have the badge, you’ll need to use BadgeService, using BadgeService.UserHasBadgeAsync. Assume that Players.PlayerAdded was fired, you have a new Player for each event. You’ll use BadgeService.UserHasBadgeAsync using their user ID and then the badge ID respectively as arguments.

Note that the function requires pcall, a protected call, in case of failures which is similar to data store functions.

The function will return a boolean, thus you have to put the line in an if-else statement without having to compare anything. The code within the if statement should either:

  • Fire to the client to make the UI appear, if the UI is not significant in any way. In this method, those UI functionalities that fire to the server has to check whether the player is in a specific list of players that has a badge, and if not, do nothing. To create that list, every time BadgeService checks if someone has a badge or giving a player the badge, add them to that table.
  • Parent the UI from the server in a storage, maybe ServerStorage, if you don’t want sneaky clients trying to break your code and find that UI specifically. The UI has to be parented to Player.PlayerGui, if it was a ScreenGui.
6 Likes

Is There Any Youtube Tutorials On This ?

There are some basic scripts here: Badges | Roblox Creator Documentation

And please please please don’t capitalize every single word in a sentence. It’s just the first word or proper names that need capital letters.

2 Likes