Hi, so for some reason I created this script where if a object is touched it gives a player a badge:
local badgeService = game:GetService("BadgeService")
local badgeId = 1022294272051045
local part = script.Parent
local function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local success, hasBadge = pcall(function()
return badgeService:UserHasBadgeAsync(player.UserId, badgeId)
end)
if success and not hasBadge then
pcall(function()
badgeService:AwardBadge(player.UserId, badgeId)
print("Badge awarded to " .. player.Name)
end)
end
end
end
part.Touched:Connect(onTouched)
(Yes i got this from chatgpt)
I have tried looking up tutorials, looking at other forums, and even asking chatgpt, but nothing has worked…
unfortunately i cant upload anything because i dont know how too
This is what looks wrong to me… can you post the badge URL.
(keep in mind I guess until I find the problem, when I don’t see it right away)
Should be able to go to that URL and copy the the badgeID.
The badge ID is supposedly not the problem then; try switching your code to this:
local badgeService = game:GetService("BadgeService")
local badgeId = 1022294272051045
local part = script.Parent
local function onTouched(hit)
local player = game.Players:GetPlayerFromCharacter(hit.Parent)
if player then
local success, info = pcall(function()
return badgeService:GetBadgeInfoAsync(badgeId)
end)
print(info.IsEnabled)
if success and info.IsEnabled then
pcall(function()
badgeService:AwardBadge(player.UserId, badgeId)
print("Badge awarded to " .. player.Name)
end)
end
end
end
part.Touched:Connect(onTouched)
To get the badge id you can go to: Creator Hub > The game you want > Engagement > Badges > Hover over the badge you want > Click the 3 dots in the top right corner of the badge icon > Click “Copy asset ID”
This code still doesnt work, and its not just the badge, ive had previous attempts trying to give a player a badge and nothing has worked, i previously assumed it depended on how far out you were, but that isnt the case
local function AwardBadge(player, badge)
local success, hasBadge = pcall(function()
return BadgeService:UserHasBadgeAsync(player.UserId, badge)
end)
if not success then
warn("Error while checking if player has badge!")
return
end
if not hasBadge then
local success, badgeInfo = pcall(function()
return BadgeService:GetBadgeInfoAsync(badge)
end)
if success then
if badgeInfo.IsEnabled then
local awarded, errorMessage = pcall(function()
BadgeService:AwardBadge(player.UserId, badge)
end)
if not awarded then
warn("Error while awarding badge:", errorMessage)
else
print("Awarding badge")
end
end
else
warn("Error while fetching badge info!")
end
end
end
Yeah it still doesnt work, also ive realized that the badgegivers in the toolbox dont work either, all the (badge giving) scripts dont give errors, or warnings. they just dont work…
Let me check If I can get my badge… I just checked and my badge didn’t work either.
I know for sure that works so… They changed something or you will have to wait a bit. They may be working on something to do with this right now. I’ll just wait and check it later.
I also checked your ID via URL and it’s there by that ID … 1022294272051045