Badges - Roblox Advanced Scripting #19 — Transcript
Full transcript
- 0:00damn this Obby looks pretty difficult
- 0:02I'm gonna see if I can do
- 0:05it uh
- 0:07oh
- 0:11no yes I did it oh it looks like I got a
- 0:15badge for it too yeah boy I did the Obby
- 0:19I can now Flex to my friends about
- 0:22this
- 0:24uh nah I am not doing that do you see
- 0:28how long that goes I am done here I
- 0:31can't believe this all right let's think
- 0:33about what we just saw for a minute when
- 0:35I finished this Obby now this was a very
- 0:37difficult Obby I will admit that once I
- 0:39ended up finishing this Obby then I
- 0:42touched this part and when I touched
- 0:43this part it showed this little
- 0:45notification down here in the bottom
- 0:46right of my screen showing that I got a
- 0:48new badge now if you're unfamiliar with
- 0:51badges essentially they are achievements
- 0:54that you can obtain in a Roblox game if
- 0:56the developer decides to add them uh and
- 0:59when you obtain the these badges they
- 1:00can appear on your profile to show that
- 1:03you have earned these badges within a
- 1:06specific game on Roblox so that's what
- 1:09I'm going to be showing you how to do
- 1:10inside of this video I'm going to be
- 1:11showing you the scripting aspect of
- 1:13implementing these badges in your Roblox
- 1:15game so with that being said let's go
- 1:17straight into implementing badges inside
- 1:19of Roblox studio now that we understand
- 1:21it let's start implementing badges in
- 1:23our Roblox game but before we can do
- 1:25that we need to make sure that we are in
- 1:28Roblox Studio on a published game so we
- 1:32can't be working on this on a local file
- 1:34because badges can only be created on a
- 1:36published Roblox game and uh if you
- 1:38don't remember how to do that we
- 1:40basically just go to the top left hit
- 1:41file and then we hit publish to Roblox
- 1:44as and then if you need to create a new
- 1:46place or overwrite an already existing
- 1:48one then you can do that but I'm already
- 1:50in a published place so I don't need to
- 1:52do that uh so once you have that taken
- 1:54care of next what we're going to do is
- 1:56start creating our badges for our game
- 1:59one one place that we can create these
- 2:01badges is within our game settings so if
- 2:03we go to home and then click on game
- 2:05settings if we go down to monetization
- 2:08then there should be a badges section
- 2:11inside of here uh ignore this badge
- 2:13that's over here but basically we can
- 2:15create a new badge clicking this create
- 2:17button next to the badges text so if we
- 2:19click on this then what should happen is
- 2:21that we should be redirected to our
- 2:23creator dashboard but in order to create
- 2:26our badges we need to locate our game
- 2:29inside of our creation inside of our
- 2:31creator dashboard so in this case my
- 2:33game is called Data store test one uh so
- 2:35in order to create a badge we need to
- 2:37click on the three dots that are on the
- 2:39top right and then click on create badge
- 2:42so now we're on this creating a badge
- 2:43page where we can upload an image for a
- 2:46badge we can make a name for it and a
- 2:47description now if we are creating a
- 2:50badge we need an image and we also need
- 2:53a name for it the description is
- 2:54optional and there is a note down here
- 2:56saying that the first five badges that
- 2:58are created are free but afterwards you
- 3:02have to pay a 100 Robux for any
- 3:03additional badges um if you decide to
- 3:06create more than five badges in your
- 3:08game but for the first five luckily
- 3:10they're free to add so uh you can add
- 3:12whatever image you want as long as the
- 3:14format is correct with one of these four
- 3:16uh it doesn't really matter what you do
- 3:18in this case so I'm just going to pick
- 3:19this one uh and then we can change the
- 3:21name of it too to let's say test badge
- 3:24one uh and then you can add in a
- 3:26description as well we could just say
- 3:29something like this is the test badge
- 3:32one okay so now that we have all this
- 3:34information filled out let's hit create
- 3:36badge so what should happen is within
- 3:39our badges section in our game our badge
- 3:42has been uploaded but our image is
- 3:44currently being under moderation right
- 3:46now so now that we have our badge we can
- 3:47go back into Roblox studio and we can
- 3:50hit the refresh button to see our badge
- 3:53displayed on our badges category so we
- 3:56have our badge here and that is how you
- 3:58create badges in Rob roblo studio now
- 4:00that we have the badge let's start
- 4:02scripting it and the first thing we're
- 4:04going to do is award this badge to the
- 4:07player if they all of a sudden decide to
- 4:09start joining into the game um we're
- 4:11going to be doing that by inserting a
- 4:13script inside of server script service
- 4:15so let's hit the plus sign let's insert
- 4:16a script now inside of our script we're
- 4:19going to need access to the badge
- 4:22service that will allow us to award our
- 4:24badge to the player so we're going to
- 4:27make reference to badge service by
- 4:29saying local badge service equals game
- 4:33colon get service badge
- 4:35service now here's something important
- 4:37to know about how do we know which badge
- 4:39we're trying to give to the player so
- 4:42whenever we're creating badges so
- 4:44whenever we're working with badges in
- 4:46order to know which badge is associated
- 4:48with what we have to refer to its badge
- 4:51ID and if you want to know where the
- 4:53badge ID of our newly created badge is
- 4:56we're going to go back to our game hit
- 4:58game settings go to monetization and
- 5:01with our badge we're going to hit the
- 5:02three dots that are to the right of it
- 5:04and we're going to click this button
- 5:06that says copy ID to clipboard so if you
- 5:09remember how assets work in Roblox
- 5:11basically the way you distinguish one
- 5:13asset from another one is by its asset
- 5:16ID but for badges they have their own
- 5:19set of IDs independent from other assets
- 5:22on Roblox so it basically works the same
- 5:24way here so we're just going to hit copy
- 5:26ID to clipboard we're going to close out
- 5:28of this and then go back to our script
- 5:30so let's make a variable to know that
- 5:32this is going to be our um badge ID so
- 5:35we're going to say local badge ID equals
- 5:38and then hit and then right click paste
- 5:42so this is our badge ID right here and
- 5:45it's this very big number right here but
- 5:47now that we have our badge ID let's make
- 5:48it so that we can award this badge to
- 5:50the player when they join into the game
- 5:52for the first time so we're going to do
- 5:53is drop two lines and then make a player
- 5:55added event so we're going to say game.
- 5:57players. player add added connect
- 6:00function open close parentheses passing
- 6:02in the player argument and so now we're
- 6:05going to immediately award the badge to
- 6:07the players since they joined into the
- 6:09game so we're going to say badge service
- 6:12colon award and this function takes in
- 6:16two arguments so the first one is going
- 6:17to be the user ID and the second one is
- 6:19going to be the badge ID which we've
- 6:21displayed up here in this variable so
- 6:23the first argument is going to be the
- 6:25player player. user ID and then then the
- 6:29second one's going to be the badge ID so
- 6:32this is a very basic implementation of
- 6:35awarding badges to the player when they
- 6:37join into the game Let's also add a
- 6:39task. weight before awarding the badge
- 6:41just so that we can give the server
- 6:43enough time for the player to join into
- 6:45the game so that we can see our badge
- 6:47being awarded on the bottom right so
- 6:49let's now join into the game and see our
- 6:52result all right so I'm in the game and
- 6:53after about a few seconds it should
- 6:55display right there saying that I have
- 6:57been awarded the test badge badge one
- 7:00because we joined into the game and we
- 7:02told badge service to award the badge to
- 7:04our player so that is basically how you
- 7:07award badges to the player in the most
- 7:09barebone basic way so since we've been
- 7:11awarded the badge we now have it but
- 7:14according to our script if we join back
- 7:16into the game then badge service will
- 7:19still then Roblox will still attempt to
- 7:21give the badge to our player despite us
- 7:23having the badge already we obviously
- 7:26don't want this to happen if we're
- 7:27already if we already obtained the badge
- 7:30so what we need to do is make a check to
- 7:32see if the player already has the badge
- 7:34and what we're going to do is use a
- 7:36function that Roblox has provided for us
- 7:39called user has badge async so the way
- 7:41this is going to work is we're basically
- 7:44going to write a variable by saying
- 7:46local has badge equals and then what
- 7:49we're going to do is say badge service
- 7:52colon user has badge async and this also
- 7:56takes in two arguments that are
- 7:57basically the same as down here the
- 7:59first first one is going to be the user
- 8:00ID and the second one is going to be the
- 8:02badge ID so we're going to say player.
- 8:05use user ID and then badge ID so this is
- 8:09going to return a Boolean to check
- 8:11whether the player has the badge or not
- 8:12and if the player does have the badge
- 8:14then we don't need to award the player
- 8:16but if they don't then we should award
- 8:19the badge to the player so we're going
- 8:21to say if not has badge so if the player
- 8:24does not have the badge then we're going
- 8:26to award the badge to theer player but
- 8:30let's say if we don't but let's say if
- 8:32the player already does then we can just
- 8:35print out saying player. name uh and
- 8:38then we can say already has the test
- 8:42badge and so this is basically how our
- 8:45script is looking now when it comes to
- 8:46checking whether the player has the
- 8:48badge or not so let's go and hit play
- 8:50again so now what should happen is we
- 8:52already have the badge so on the output
- 8:55it should say that the player already
- 8:57has the test badge as you can see down
- 8:58here it's not going to award it to us
- 9:00because we already have it so there's
- 9:02another thing we can do with Badges and
- 9:03that's obtaining information about a
- 9:06specific badge if we need it in our
- 9:08Roblox game so right now I'm back in the
- 9:10Creator Hub and I'm checking the
- 9:12overview of the badge that we just
- 9:13created so we have things like our name
- 9:16the image the description and whether
- 9:18you can obtain this badge or not with
- 9:20these four bits of information we can
- 9:22actually retrieve this information in
- 9:24Roblox studio if we need it within the
- 9:26game specifically this so with what I'm
- 9:29about to show you we're able to access
- 9:31the name of the badge the description of
- 9:33the badge uh whether you can obtain it
- 9:35or not and the ID of the image so not
- 9:39the ID of the badge but the ID of the
- 9:42image for the badge so with that being
- 9:44said let's go back into studio and
- 9:46implement this so now that we're here
- 9:48we're going to use a method that will
- 9:51give us a table full of the information
- 9:52that we need called get badge info async
- 9:56so this is what it's going to look like
- 9:57we're going to make another variable by
- 9:59saying local badge info equals badge
- 10:04service colon get badge info async and
- 10:09the only argument that this needs is the
- 10:12badge ID which we already have as a
- 10:14variable so we're going to say badge ID
- 10:16and this is going to return a table full
- 10:18of information that we're going to use
- 10:21um inside of Roblox studio so if we
- 10:23let's say decided to Loop through all
- 10:26the values inside of our badge info
- 10:29variable uh so let's just do this really
- 10:31quick by putting in badge info do and
- 10:35then print V if we just go into the game
- 10:39and uh see the if we just go into the
- 10:41game and see the output uh what should
- 10:44be down there is okay so we have true
- 10:48and then this massive number and then we
- 10:50have the name of our badge and then we
- 10:51have the description of the badge so you
- 10:53can kind of get what sort of information
- 10:55is in here because I explained this
- 10:56earlier uh we have the badge name we
- 10:59have the badge description we have
- 11:01whether this is active or not and we
- 11:03have the ID of the image itself so if we
- 11:07want to be more specific about getting
- 11:10which information we can use the
- 11:12properties that badge info has just by
- 11:14saying print badge info. name so that is
- 11:20basically fetching the name of the badge
- 11:22and then we have badge
- 11:24info. description which gives us the
- 11:27description obviously and then we have
- 11:29badge info. is enabled which is the
- 11:33third property that tells us whether you
- 11:35can actually obtain this badge and then
- 11:37finally the last one is called icon
- 11:40image ID so these are the four
- 11:43properties that badge info has for us to
- 11:45use in a Roblox game in case we do need
- 11:48this information from the badge itself
- 11:50so that is another neat thing we can do
- 11:52with these badges in our game Okay so
- 11:54we've basically went over everything
- 11:56badge service has to offer but if I'm a
- 11:59be honest we did a pretty sloppy job
- 12:00with adding all of these different
- 12:02features that badge service has to offer
- 12:04it works but it is pretty unsecure with
- 12:07the way we've been trying to implement
- 12:08uh these features in Roblox studio so
- 12:10what we're going to do is add PE calls
- 12:13to our scripts so if you've been
- 12:15following along with my Advanced
- 12:16scripting series you might be familiar
- 12:19with PE calls because I explained how to
- 12:21use them uh when we're working with data
- 12:23stores and the same principle basically
- 12:26applies here with badge service because
- 12:28we're using functions that could be
- 12:30interrupted by the network when we're
- 12:32trying to do something and there is a
- 12:34very high possibility that it might not
- 12:37go through with what we're trying to do
- 12:39whether that would be trying to whether
- 12:41that would be trying to figure out
- 12:42whether the player has a badge or
- 12:44whether we were able to award the badge
- 12:46properly or whether we were able to get
- 12:48information about a badge specifically
- 12:50if we aren't certain about whether this
- 12:52is going to go through or not we need to
- 12:54know why it doesn't go through so that's
- 12:56why we need to use PE calls but here's
- 12:58but here's another thing I haven't
- 13:00really explained the syntax of PE calls
- 13:03and the different ways you can write PE
- 13:05calls when using this you still might be
- 13:06confused about why a PE call is
- 13:09structured the way it is so there's two
- 13:11ways of writing PE calls and the reason
- 13:13I'm explaining this is because we're
- 13:14going to be using the second way of
- 13:16writing PE calls that I haven't showed
- 13:18you yet so before we Implement that I
- 13:19want to show you how this works so
- 13:21there's two ways of writing PE calls and
- 13:23I've showed you how to do the first one
- 13:25if you've been following my Advanced
- 13:26scripting tutorial series because I did
- 13:28this when I was teaching you how to do
- 13:30data stores but it looks something along
- 13:32the lines of this so if I have our
- 13:34success variable like this with our
- 13:37error message right here uh this is
- 13:40basically going to tell us that if the P
- 13:41call failed then we're going to print
- 13:43this message but if it was successful
- 13:45then we're going to know with this
- 13:46Boolean value we're going to set this
- 13:48equal to P call function open close
- 13:50parentheses enter so this is this has
- 13:53been the structure of our PE call but
- 13:55now you might think why is it like this
- 13:58what's the significance of this syntax
- 14:01structure so I kind of want you to think
- 14:04of it like this if I let's say deleted
- 14:06these lines that are empty right
- 14:09here this is how you define a function
- 14:12so you have the function keyword uh with
- 14:15the open and close parenthesis and then
- 14:17you end it with an end statement and
- 14:18then between here is the the body of
- 14:21code so this is how you create a new
- 14:24function um and this is basically one
- 14:27argument in this PE call but then
- 14:30everything up until this point is any
- 14:32external argument that's going to be
- 14:34passed into these parameters that are
- 14:36inside of this function that you just
- 14:37created what I'm talking about is let's
- 14:40say I had a parameter in here called
- 14:42number one uh if I wanted to pass in a
- 14:45number that Associates with this
- 14:48parameter right here I'm going to pass
- 14:50it in after this function call right
- 14:52here so this can be whatever number I
- 14:54want it can be 100 so the first argument
- 14:57is going to be the function the second
- 14:59one is going to be any Associated
- 15:02arguments that are going to be passed
- 15:04into these parameters right here and so
- 15:06if I basically drop a line down here
- 15:08with the function this is basically what
- 15:11we had before with our PE call but this
- 15:13time we're adding in a parameter with an
- 15:17argument associated with it and this is
- 15:19how you structure the first PE call so
- 15:22if I let's say printed number one then
- 15:25what's going to happen is if I hit run
- 15:26inside of rope blocks then in the output
- 15:29it should print the number 100 because
- 15:31we were successfully able to know
- 15:33whether we were able to have this go
- 15:36through successfully or not and so this
- 15:37is one way of structuring PE calls and I
- 15:39hope that made sense to you okay but now
- 15:41I'm going to show you the second way of
- 15:42writing a PE call so this one takes in
- 15:45two required functions on top of any
- 15:48additional arguments that you want to
- 15:49put so for for our first example we only
- 15:52put in one required argument which was
- 15:55our function that we just created but
- 15:57this time if we let's say wanted to use
- 16:00a method from a specific class that
- 16:03Roblox has to offer which in this case
- 16:06we're going to be using a method from
- 16:07badge service we're going to need to
- 16:09specify which service we're trying to uh
- 16:12use and which method from that service
- 16:14we're trying to use so this is what it's
- 16:17going to look like we're going to have
- 16:19our same signature which is going to be
- 16:20local success error message we're going
- 16:24to set this equal to P call again but
- 16:25this time this is going to take in two
- 16:27parameters so the first one is going to
- 16:30be the the method of the class that
- 16:32we're trying to uh use rather than our
- 16:35own function that we're trying to create
- 16:37so so we're trying to use an existing
- 16:39function we're going to say badge
- 16:42service colon Award badge let's say in
- 16:46this case we're not going to put in any
- 16:47open and close parentheses we're just
- 16:49going to have it like this and then our
- 16:51second argument is going to be the
- 16:52instance also known as the service
- 16:55itself that we're going to pass in so
- 16:57it's going to just be badg service we're
- 16:58going to pass in badge service and then
- 17:02the rest are just additional arguments
- 17:04that we need to pass in but in this case
- 17:06we actually do need to pass in two
- 17:08arguments because we're trying to pass
- 17:11them into our Award badge method which
- 17:14if you remember Award badge takes in two
- 17:16arguments which the first one is the
- 17:18user ID and the second one is the badge
- 17:20ID so in this case we have to pass in
- 17:22our two parameters which is going to be
- 17:24the player. user ID but the thing is uh
- 17:27we're not inside of our uh player added
- 17:30event so we're actually going to copy
- 17:31this and we're going to paste this down
- 17:33here so that's going to take in our
- 17:36first argument the second one is going
- 17:37to be the badge ID because when we call
- 17:40Award badge we need to pass in the two
- 17:44arguments that need to be inside of a
- 17:46word badge which the first one's going
- 17:47to be the user ID and the second one is
- 17:48going to be the badge ID and the second
- 17:50argument is just going to be the
- 17:52instance of the method that we're trying
- 17:54to use okay so instead of using a colon
- 17:56we're actually going to use a DOT
- 17:57because award word badge in this case
- 18:00we're just trying to get the method of
- 18:01the service we're not trying to call it
- 18:03because if we were to try and call it we
- 18:04would use the colon with the open close
- 18:07parentheses like this but we're not
- 18:08going to do it like this uh we just need
- 18:10the method itself so that's why we're
- 18:12going to use a DOT and this is
- 18:14essentially the second way of how you
- 18:17write PE calls and I hope this analogy
- 18:19made sense to you okay but now let's go
- 18:21back and fix our already existing script
- 18:24to add PE calls to make it more safe so
- 18:26I'm going to block out uh this comment
- 18:29that I have down here and what we're
- 18:30going to do is copy what we had for our
- 18:33Award badge PE call and we're going to
- 18:36put this up here so we're going to paste
- 18:37it over here and we should have a
- 18:39success to tell us whether uh Award
- 18:42badge has been successful and so just to
- 18:44make this a little easier we're going to
- 18:46comment out everything we've had here up
- 18:48until this point so what let's say this
- 18:51did not go through let's check if this
- 18:53was not successful for awarding the
- 18:56badge to the player then what we're
- 18:57going to do is print out the error
- 19:00message so this is a more secure way of
- 19:04awarding the badge to the player just so
- 19:06that we know that it is possible just so
- 19:09that we know that it is possible to get
- 19:11errors when it comes to awarding uh the
- 19:13badge to the player so this is how you
- 19:15do it in a more secure way okay but now
- 19:17let's say we wanted to further improve
- 19:19on this by checking whether the player
- 19:21already has the badge or not so what
- 19:22we're going to do is say local has badge
- 19:27error message equals success has badge
- 19:33equals P call open and close parentheses
- 19:36what we're going to do is use the user
- 19:39has async user has badge async that we
- 19:42had down here uh as our first argument
- 19:44so we're just going to say badge
- 19:46service. user has badge async and then
- 19:51our second argument is going to be badge
- 19:53service itself and then we're going to
- 19:56pass in our two arguments that are
- 19:57required re ired for user has badge
- 19:59async which is going to be the player.
- 20:02user ID and then finally the badge ID
- 20:05and so now that we have that let's check
- 20:07if this wasn't successful so we're going
- 20:09to say if not success then we're just
- 20:12going to print out some error message
- 20:14saying that uh that we failed to get the
- 20:18that we failed to check if the player
- 20:19has the badge so we're going to say
- 20:21failed to check if player has badge okay
- 20:26and then what we're going to do is drop
- 20:28down here and say if has badge so if the
- 20:31player actually does have badge since
- 20:32user has badge async will return whether
- 20:35um the user has the badge or not we're
- 20:36going to take our original P call with
- 20:39awarding the badge and we're going to
- 20:41put this inside of our has badge if
- 20:43statement so already now what we've done
- 20:46is checked if the player has the badge
- 20:48or not in a more successful way and if
- 20:50they do then we're going to securely
- 20:53award the badge to them and finally
- 20:55we're going to get the badge info in a
- 20:57more secured way and this is what we're
- 20:58actually going to do to check whether we
- 21:00can actually award this badge or not so
- 21:03here's what we're going to do at the
- 21:04very beginning we're going to get the
- 21:06badge information so we're going to say
- 21:08local success to check whether this was
- 21:10successful again but then this time
- 21:12we're going to say badge info equals P
- 21:15call open close parenthesis we're going
- 21:17to write our P call the second way just
- 21:19like uh we've done every other time so
- 21:21we're going to say badge
- 21:23service. get badge info async and then
- 21:28then our second argument is just going
- 21:29to be badge service again and then this
- 21:31time badge get badge info async only
- 21:34takes in one argument which is just the
- 21:36badge ID so that's what we're going to
- 21:37put down here so what we're going to do
- 21:39is we can check whether this was
- 21:40successful or not successful but in this
- 21:42case what we're going to do is check if
- 21:44this was not successful then we're going
- 21:46to say if not success then we're going
- 21:50to print failed to get badge
- 21:54information okay and so now that we have
- 21:56this check for whether whether we
- 21:58weren't able to obtain the badge and
- 22:00this check whether the player already
- 22:01has the badge now we can finally go down
- 22:04here to actually award the badge to the
- 22:05player now here's another thing we can
- 22:08do to make sure that we can actually add
- 22:11that we can actually award the player
- 22:13the badge now that we have our badge
- 22:15info is if you remember we can check
- 22:17whether this badge is enabled so we can
- 22:20actually make that check down here
- 22:21before we award the badge to the player
- 22:23so what we're going to do is we're going
- 22:25to say if has badge and
- 22:28badge info. is enabled then we're going
- 22:32to attempt to award the badge to the
- 22:35player and so finally we've reached the
- 22:37end of our script in the most secure way
- 22:40possible at least to the way that I see
- 22:42it so this has basically been adding
- 22:44badges in Roblox Studio but of course
- 22:47you can experiment around with this and
- 22:49try to add even more badges if you were
- 22:51to loop loop all these around in a table
- 22:54uh to try and award specific badges to
- 22:56specific players if you decide to do so
- 22:58this is generally the way that we script
- 23:00badges in Roblox studio and I want you
- 23:02to get into the practice of writing
- 23:04these PE calls to make them more secure
- 23:06when you're trying to add them so that
- 23:08is basically going to be it for Badges
- 23:09and I hope you found this video to be
- 23:11helpful if you're still confused about
- 23:12peac calls I have another video where I
- 23:15go into PE calls in my data store video
- 23:17which I'm going to have a link for you
- 23:19right here to watch if you're interested
- 23:21but with that being said be sure to
- 23:22check out the rest of my playlist for my
- 23:23Advanced scripting tutorial guide and I
- 23:25will be seeing you in the next episode
- 23:28take care
About this transcript
This page contains the full transcript of Badges - Roblox Advanced Scripting #19 by BrawlDev, generated from the public captions YouTube serves with the video. The transcript has 4,720 words across 615 segments, with the original timestamps preserved so you can click any line to jump to that moment in the embedded player.
What you can do with it
Use the transcript to take notes, quote the speaker, build a study guide, generate a summary with ChatGPT or Claude via the YouTube Summary tool, or export it as a timed subtitle file with YouTube to SRT. You can also re-open it in the transcriber to choose a caption track available on the video.
Free YouTube transcript tool
YouTube2Text is a free YouTube transcript generator — no signup, no daily limit. Paste any YouTube link and get the full transcript instantly, with timestamps, click-to-jump, caption language selection, AI prompts for ChatGPT, Claude, and Gemini, and exports to TXT, SRT, VTT, or Markdown.