Hey uh, I’m right now making a game like Clicking Simulator, I added some badges and I know how to script one of them, but another I don’t know how to. I need to script a NPC like, when you touch him you will get specific badge.
If you insert a script into a part and write this code:
local badgeservice = game:GetService("BadgeService")
local id = 000 -- Your badge ID here
-- Part touched
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid")then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
badgeservice:AwardBadge(plr.UserId,id)
end
end)
This will award the player a badge when they touch the part.
I made part and put in it script, touching the part but it not gives me badge.
If you are testing in studio it might not give you the badge. It may not show that you received badge as it may already be in your account.
I didn’t test in studio, touched part in the game with published changes, not giving.
Have you checked your badges in your account? It might have already be collected without noticing?
Checked badges, it’s not in my inventory.
I think to check if there’s a mistake in script we can make printing part. Like if it didn’t give me badge it will print some text.
Does it have an error or yields in the output?
Nothing in output when touching the part that must give me the badge.
Try using the article I sent to you above.
Tried to use, still not working.
What’s the script in your part now?
Did you make it a local script or a server script?
Roblox made it so that the badge can only be given by the Server. RemoteEvent might be required.
Normal script in part that person must touch
local BadgeService = game:GetService("BadgeService")
local BadgeId = 2125872275
local function awardBadge(player, badgeId)
-- Fetch badge information
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badgeId)
end)
if success then
-- Confirm that badge can be awarded
if badgeInfo.IsEnabled then
-- Award badge
local success, result = pcall(function()
return BadgeService:AwardBadge(player.UserId, badgeId)
end)
if not success then
-- the AwardBadge function threw an error
warn("Error while awarding badge:", result)
elseif not result then
-- the AwardBadge function did not award a badge
warn("Failed to award badge.")
end
end
else
warn("Error while fetching badge info: " .. badgeInfo)
end
end
Simplest script I’ve ever done.
[if there’s something that you don’t like just change it ig]
And I use this for one of my games, so it’s impossible for it to not work. Place it as a sibling in a part [the part you need to touch to get a badge or make a hitbox of it] make sure “CanTouch” is ✓
if part.Parent:FindFirstChild("Humanoid") then
local player = game.Players:GetPlayerFromCharacter(part.Parent)
game:GetService("BadgeService"):AwardBadge(player.UserId, 000) -- Put your badge id
end
end)