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.
1 | local BadgeService = game:GetService( "BadgeService" ) |
2 | local BadgeId = 0000 --Your badge Id here |
3 |
4 | if BadgeService:UserHasBadgeAsync(game.Players.LocalPlayer.UserId, BadgeID) then |
5 |
6 | end |
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 )
01 | local BadgeTool = -- The Tool |
02 | local BadgeID = --- BadgeID |
03 |
04 | game.Players.PlayerAdded:Connect( function (Player) |
05 | Player.CharacterAdded:Connect( function (Character) |
06 | if BadgeService:UserHasBadgeAsync(Player.UserId, BadgeID) then |
07 | local PlayersBackpack = Player:WaitForChild( "Backpack" ) |
08 | local ClonedTool = BadgeTool:Clone() |
09 | ClonedTool.Parent = PlayersBackpack |
10 | end |
11 | end ) |
12 | end ) |
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:
01 | local BadgeService = game:GetService( "BadgeService" ) |
02 | local BadgeId = 0000 --Your badge Id here |
03 | local tool -- tool here |
04 | game.Players.PlayerAdded:Connect( |
05 | function (plr) |
06 | plr.CharacterAdded:Connect( |
07 | function (Character) |
08 | if BadgeService:UserHasBadgeAsync(plr.UserId, BadgeID) then |
09 | tool:Clone().Parent = plr.Backpack |
10 | end |
11 | end |
12 | ) |
13 | end |
14 | ) |