Help with a badge script

Hello there Fellow Developers i need some help today,

how do i make a script that when you unlock a badge you get a Secret gear in my game

if you know how to do it please tell me i really wanna know

–Your Friend Teyougin

:slight_smile: :slight_smile: :slight_smile:

Use BadgeService, its a handy service that allows you to grant and check for badges.

local BadgeService = game:GetService("BadgeService")
local badgeId = 0
function cloneTool(Player : Player)
    -- do you stuff
end
game:GetService("Players").PlayerAdded:Connect(function(plr)
    local success, PlayerHasBadge = pcall(function()
        return BadgeService:UserHasBadgeAsync(plr.UserId, badgeId)
    end)
    if PlayerHasBadge then
        cloneTool(plr)
    end
end)
1 Like

Do some reasearch on google. Badges

This should cover the basics. Check if player owns a badge, if they do, clone the tool to their backpack.

Use a script that utilizes UserHasBadgeAsync:

local bservice = game:GetService("BadgeService")
local players = game:GetService("Players")
players.PlayerAdded:Connect(function(player)
 	local success, hasBadge = pcall(function()
		return bservice:UserHasBadgeAsync(player.UserId, badgeID)
	end)
	if hasBadge then
		local tool = game:GetService("ReplicatedStorage").gear:Clone()
		--put variable tool into player's backpack
	end
end)

(referenced from BadgeService:UserHasBadgeAsync)

thank you very much you have been so helpful

1 Like

Quick Note: I made sure to add a player argument to the cloneTool() function to retrieve the player.

1 Like

Thank you to everyone who helped me out, here is the code

-- local BadgeService = game:GetService("BadgeService") local Tool = game:GetService("ReplicatedStorage"):WaitForChild("Tool") -- Change tool to the name of your tool in replicated storage! local BadgeId = Your Badge ID here! game.Players.PlayerAdded:Connect(function(player) if BadgeService:UserHasBadgeAsync(player.UserId,BadgeId) then Tool:Clone().Parent = player.Backpack Tool:Clone().Parent = player.StarterGear end end)

i know the post looks a little off but i have never used a lua code thing in the devforum before