So you heard about Roblox making the first 5 badges free? (Announcing Free Badge Creations!) It didn’t take me much to find out. Well, since I know that some games have a badge that gives you a gear, I thought to make one!
How do I make a badge script that gives you a tool?
I tried to look on youtube and the Dev hub, but I haven’t found anything. Quite surprised, everyone knows that there’s a system that gives a badge, don’t they know?
If anyone has a video/or article, please send me! Thanks!
local bs = game:GetService("BadgeService")
local id = 0000000
game.Players.PlayerAdded:Connect(function(plr)
bs:UserHasBadge(plr.UserId, id) and print(plr.Name.." have the badge!") or print(pr.Name.." dont have the badge")
--- you also can use if statement
end)
Checking if a player has a badge then giving that tool kind of already works as its own saving since the server will always check the players badges upon them joining and still giving them the assigned gear/tool.
BadgeService is a service which allows you to interact with website badges in ways such as awarding a player a badge, checking the badge ownership, getting info about a badge and running code when the badge is awarded. Here is a code sample which gives a tool to a player if they have a badge, every time they respawn:
--Script inside StarterCharacterScripts
local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")
local BadgeId = 0
local Character = script.Parent
local Player = Players:GetPlayerFromCharacter(Character)
local tool = game.ServerStorage:WaitForChild("Tool") --tool location
--you may want to pcall the request, in case it fails(although it will only effect the current player spawn)
local owned = BadgeService:UserHasBadgeAsync(Player.UserId, BadgeId)
function giveTool()
tool:Clone().Parent = Character --parenting to character auto equips the tool(else parent to Player.Backpack)
end
if owned then
giveTool()
end
--in case the badge is awarded while the player is alive
BadgeService.OnBadgeAwarded:Connect(function(userId, creatorId, badge)
if userId == Player.UserId and badge == BadgeId then
giveTool()
end
end)
game.Players.PlayerAdded:Connect(function(Player)
local ownsBadge = game:GetService(“BadgeService”):UserHasBadge(Player.UserId,2124792273)-- put your badge Id here
if ownsBadge then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
correct me if something wrong i didn’t test it yet
If you are talking about event items, they cannot be awarded without Roblox being involved. So, without a partnership with Roblox, that would be impossible.
ocal Tool = script.SpeedCoil-- the tool
game.Players.PlayerAdded:Connect(function(Player)
local ownsBadge = game:GetService(“BadgeService”):UserHasBadge(Player.UserId,2124792273)-- put your badge Id here
if ownsBadge then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)
local Tool = script.Tool-- the tool
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2124934047 --put your badge Id here
game.Players.PlayerAdded:Connect(function(Player)
local ownsBadge = BadgeService:UserHasBadge(Player.UserId,BadgeId)
if ownsBadge then
local ToolClone = Tool:Clone()
ToolClone.Parent = Player.Backpack
end
end)