Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 4 years ago
Edited 4 years ago

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
0
tool.Parent = player.Backpack raid6n 2196 — 4y
0
i the script a server script raid6n 2196 — 4y
0
edited my answer raid6n 2196 — 4y

2 answers

Log in to vote
0
Answered by
Zero_Tsou 175
4 years ago
Edited 4 years ago

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)
0
gg beat me to it raid6n 2196 — 4y
0
Welp lol Zero_Tsou 175 — 4y
Ad
Log in to vote
0
Answered by
raid6n 2196 Moderation Voter Community Moderator
4 years ago
Edited 4 years ago

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
)
0
Do I put all of that into ServerScriptService? stickymirro511 61 — 4y
0
No. raid6n 2196 — 4y
0
wait, is the first script a server script? raid6n 2196 — 4y
0
I assume it is. stickymirro511 61 — 4y
0
edited raid6n 2196 — 4y

Answer this question