I want to award a badge to the player who killed (can be last hit) that monster. Im using a JeffTheKiller Model with scripts and Humanoid. When I kill it nothing happens. I don't know how to manage creator tags. I tried to put the following script under my Humanoid:
function AwardBadge(player, badgeId)
local success = false
local badgeInfo = nil
local attempts = 0
repeat
attempts += 1
success, badgeInfo = pcall(function()
return game:GetService("BadgeService"):GetBadgeInfoAsync(badgeId)
end)
if not success then wait(5) end
until
success or attempts >= 3
if success then
if badgeInfo.IsEnabled then
local err = nil
success = false
attempts = 0
local HasBadge = false
repeat
attempts += 1
success, err = pcall(function()
HasBadge = game:GetService("BadgeService"):UserHasBadgeAsync(player.UserId, badgeId)
end)
if not success then wait(5) end
until
success or attempts >= 3
if HasBadge then return end
success = false
attempts = 0
err = nil
repeat
attempts += 1
success, err = pcall(function()
game:GetService("BadgeService"):AwardBadge(player.UserId, badgeId)
end)
if not success then wait(5) end
until
success or attempts >= 0
if not success then
warn("Error while awarding badge: ", err)
end
end
else
warn("Error while fetching badge info: "..badgeInfo)
end
end
script.Parent.Died:Connect(function()
local creator = script.Parent:FindFirstChild("creator")
if creator ~= nil then
AwardBadge(creator.Value, 2124659474)
end
end)
