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

How do I make it, when a player has a badge, he earn a tool?

Like, if you have a badge, then he get a item from the catalog?

Thanks!

Follow me on ROBLOX Click Here

2 comments

0

Wow, already -1, :,(

0

do not put requests for people to follow you in your questions, also supply code with your questions, and accept personacole's answer

1 answer

✓ Accepted answer

There is a special service provided for badges. There is a wiki page here.

So we need to use the service using the method :GetService() from the game. We then use a function to check every time a player joins to see if he has a badge. I literally copied the script from the wiki but hey, faster answer response for you and easier work for me. Plus, I already knew this.

local BadgeService = game:GetService("BadgeService")
local BadgeId = 123
 
game:GetService("Players").PlayerAdded:connect(function(player)
    if BadgeService:UserHasBadge(player.UserId, BadgeId) then
        item = game:GetService("ReplicatedStorage").SpecialItem
	item:Clone().Parent = player:WaitForChild("Backpack")
    else
        print("The user does not have this badge")
    end
end)

Change "123" at local BadgeId = for the correct ID. Put your special item in ReplicatedStorage so that the script can pick it up. You can either change the name of the item to SpecialItem or change the name of SpecialItem inside the script.

If you don't care about the other result where the player wouldn't have the badge, just remove else and the print command.

EDIT: Sorry, I thought it was a gamepass, I corrected it to the badge instead. But for gamepasses and developer products, they require a different service called MarketplaceService.

2 comments

0

He'd actually want to use UserHasBadge.

0

Oops. My mistake.

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