My script is not working. It is supposed to award a badge to the player who touched a specific part (the script’s parent). CanTouch of the part is checked. And other parts with the same script gave me badges perfectly fine, in fact this part is a duplicate of the other parts. I do not have the badge in my Roblox inventory and I have tried this script in public servers but it still does not work.
My script:
local BadgeService = game:GetService("BadgeService")
local id = 000 -- badge id
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = game.Players:GetPlayerFromCharacter(hit.Parent)
if not BadgeService:UserHasBadgeAsync(plr.UserId, id) then
BadgeService:AwardBadge(plr.UserId, id)
end
end
end)
The part and script:
I got badges from other parts with the exact script, just with different badge id, but in this part, it doesn’t work.
local BadgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")
local id = 000000 -- badge id
script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
local plr = PlayerService:GetPlayerFromCharacter(hit.Parent)
local success,result = pcall(function()
return BadgeService:UserHasBadgeAsync(plr.UserId,id)
end)
if success then
if result then -- if he has the badge
warn("already owns")
else
--award him
end
end
end
end)