What a badge hitbox is and why you need one
A badge hitbox in Roblox Studio is an invisible collision box that triggers when a player touches it, usually to award them a badge or unlock an achievement. Unlike a visible part, the hitbox itself has no appearance — it's purely functional. You create it by making a part, turning off its visibility, and writing a script that detects when a player's character enters that space.
Most games use badge hitboxes at specific locations: the end of an obstacle course, inside a secret room, at the top of a tall structure. The hitbox stays in place, and whenever any player walks through it, the script checks whether they've already earned that badge, then grants it if they haven't.
Key Takeaways
- A badge hitbox is a transparent part with a script attached that detects player contact and triggers a badge reward.
- You create the part in the workspace, set CanCollide to false so players walk through it, and make it invisible by setting Transparency to 1.
- The script uses the Touched event to detect when a player enters the hitbox and calls the BadgeService to award the badge.
- You must create the badge itself in the Game Passes and Badges section of your game's settings before the script can award it.
- Testing in Studio requires you to run the game, walk your character into the hitbox, and check the Output window for errors or confirmation messages.
Creating the part and configuring its properties
Start by inserting a new part into your workspace. In Roblox Studio, go to the Insert menu, select Part, and choose a shape — a block or sphere works fine. Position it where you want the badge to trigger: at a checkpoint, inside a treasure chest, or anywhere else in your game world.
Next, open the Properties panel on the right side of Studio. Find the part you just created in the Explorer tree and click it. In Properties, change these settings: set CanCollide to false (so players walk through it instead of bumping into it), set Transparency to 1 (so it becomes completely invisible), and set Name to something clear like "BadgeHitbox" or "SecretRoomTrigger". Leave CanQuery as true — this lets scripts detect it.
You can also set TopSurface and BottomSurface to Smooth if you want, though it doesn't matter since the part is invisible. The size of the part determines the size of the trigger zone, so make it large enough that players will definitely touch it when they reach the intended location.
Writing the script that detects player contact
Right-click the part in the Explorer, select Insert Object, and choose Script. A new script window opens. Delete the default code and paste this:
local badgeId = 123456789 local hitbox = script.Parent local debounce = {} hitbox.Touched:Connect(function(hit) local humanoid = hit.Parent:FindFirstChild("Humanoid") if not humanoid then return end local player = game.Players:GetPlayerFromCharacter(hit.Parent) if not player then return end if debounce[player.UserId] then return end debounce[player.UserId] = true game:GetService("BadgeService"):AwardBadge(player.UserId, badgeId) print(player.Name .. " earned the badge!") end)
Replace 123456789 with your actual badge ID. You'll get this number from your game's settings (see the next section). The script waits for the Touched event, checks whether the thing that touched it is a player character, prevents the same player from triggering it multiple times in quick succession using a debounce table, and then awards the badge using BadgeService.
The debounce prevents a player from earning the badge ten times in one second if they stand on the hitbox. Once they leave and come back, the debounce clears and they can earn it again — or the script can be modified to only allow one badge per player ever.
Creating the badge in your game settings
Before the script can award anything, the badge must exist. Go to the Roblox website, log in, and navigate to your game's settings. Click the Monetization tab, then Badges. Click Create Badge. Give it a name (like "Secret Room Found"), write a description, and upload an icon image (it should be at least 512 by 512 pixels). Click Create.
Roblox will assign the badge an ID number. Copy that number and paste it into your script where it says badgeId = 123456789. Save the script. Without this step, the script will run but the badge won't actually be awarded because it doesn't exist in your game's system.
Testing the hitbox in Studio
Click the Play button in Studio to start a test session. Your character will spawn into the game. Walk or move your character into the hitbox area. If everything is set up correctly, you'll see a message in the Output window (View menu > Output) that says something like "YourUsername earned the badge!" or an error message if something went wrong.
Common errors: if you see "BadgeService is not available in Studio", that's normal — badges only award in live games, not in Studio tests. If you see "attempt to index nil with 'UserId'", the player detection failed, which usually means the part isn't positioned where your character actually touches it. If you see no message at all, check that your script is a Script (not a LocalScript) and that it's inside the part.
Once you publish your game, test it again by joining your own game from the Roblox website. Walk into the hitbox. The badge should appear in your inventory after a few seconds.
Modifying the script for different badge behaviors
The basic script awards the badge every time a player touches the hitbox, but you can change this. To award a badge only once per player ever, replace the debounce section with a datastore that records who has earned it. To award a badge only if the player has a certain item or has completed a task, add an if statement before the AwardBadge line that checks that condition.
To make the hitbox disappear after someone earns the badge, add hitbox:Destroy() after the AwardBadge line. To make it only award badges to players in a certain group, add a check using player:IsInGroup(groupId). The Roblox API documentation has examples of all these patterns.
Troubleshooting hitbox problems
If players report that they walked through the area but didn't get the badge, the hitbox might be positioned wrong, too small, or the script might have an error. Check the Output window while testing — errors show up there. Make sure CanCollide is false and Transparency is 1; if either is wrong, the hitbox won't work as intended.
If the same player keeps earning the badge over and over, the debounce might not be working. Check that the script is a Script (not a LocalScript) and that it's inside the part. If multiple players are earning badges at the exact same moment, there might be a race condition in the script, but this is rare in small games.
If the badge shows up in your game's badge list but players aren't earning it, double-check that the badgeId number in your script exactly matches the ID shown in your game settings. Even one digit off will cause it to fail silently.
Frequently Asked Questions
Can I make the hitbox visible so I can see where it is while building?
Yes. While building, set Transparency to 0 so you can see the part. Once you're done positioning it, set Transparency back to 1 before publishing. You can also set the part's Color to something bright like red or yellow while building, then change it back to a neutral color before making it invisible.
What's the difference between a Script and a LocalScript for the badge hitbox?
Use a Script, not a LocalScript. Scripts run on the server and can use BadgeService. LocalScripts run only on the player's computer and cannot award badges. If you accidentally use a LocalScript, the badge won't be awarded even if the script runs without errors.
Can I award multiple badges from one hitbox?
Yes. Add more lines like game:GetService("BadgeService"):AwardBadge(player.UserId, badgeId2) and game:GetService("BadgeService"):AwardBadge(player.UserId, badgeId3) after the first AwardBadge line. Each badge needs its own ID from your game settings.
Do I need to make the hitbox a certain size?
No. Make it as large or small as you need. A larger hitbox is easier for players to trigger accidentally, while a smaller one requires precision. For a checkpoint at the end of an obstacle course, a hitbox the size of a door frame usually works well.
What happens if a player earns a badge they already have?
Nothing. Roblox prevents duplicate badges automatically. If a player has already earned a badge and touches the hitbox again, the script will try to award it, but the player's inventory won't change and no error occurs.