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

If player owns a badge it awards a tool. Anyone know how to do that?

I have a script that checks if a player owns a badge, but I don't know how to make it award the tool. If you could help, that would help a lot.

local BadgeService = game:GetService("BadgeService")
local BadgeId = 0000 --Your badge Id here

if BadgeService:UserHasBadgeAsync(game.Players.LocalPlayer.UserId, BadgeID) then
    
end

3 comments

0

tool.Parent = player.Backpack

0

i the script a server script

0

edited my answer

2 answers

✓ Accepted answer

You can use a PlayerAddedEvent which fires whenever the player joins and a characterAdded Event which does the same But for the Player's character ( fires whenever the character respawns/spawn )

local BadgeTool = -- The Tool
local BadgeID = --- BadgeID

game.Players.PlayerAdded:Connect(function(Player)
	Player.CharacterAdded:Connect(function(Character)
		if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeID) then
				local PlayersBackpack = Player:WaitForChild("Backpack")
				local ClonedTool = BadgeTool:Clone()
				ClonedTool.Parent = PlayersBackpack
			end
	end)
end)

2 comments

0

gg beat me to it

0

Welp lol

You could do tool:Clone().Parent = player.Backpack. (Also, you can't use local player in a server script, so ill just use a player added event)

Server script:

local BadgeService = game:GetService("BadgeService")
local BadgeId = 0000 --Your badge Id here
local tool  -- tool here
game.Players.PlayerAdded:Connect(
    function(plr)
        plr.CharacterAdded:Connect(
            function(Character)
                if BadgeService:UserHasBadgeAsync(plr.UserId, BadgeID) then
                    tool:Clone().Parent = plr.Backpack
                end
            end
        )
    end
)

5 comments

0

Do I put all of that into ServerScriptService?

0

No.

0

wait, is the first script a server script?

0

I assume it is.

0

edited

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