[SOLVED] Badge giver script not working

Adding to what mentioned above,
you should always wrap such calls in pcalls. Example:

local success,result = pcall(function()
    return game:GetService("BadgeService"):UserHasBadgeAsync(Player.UserId,BadgeID)
end)

if success then
   if not result then
    --award him here.
   end
end

it didn’t work i putted the print thing it worked, but the badge still didnt award i do not know why
agdshfnm

As @Valkyrop said you should check if the player first has a badge so to do this I would do it like this:

local ball = game:GetService("Workspace").ball
local BadgeID = 2127919489

game:GetService("Workspace").DescendantRemoving:Connect(function(descendant) --RBXScriptSignal that gets fired when something is removed from workspace
    if descendant == ball then -- The object that is being removed is the ball
        for _,v in pairs(game:GetService("Players"):GetPlayers()) do
            local success,hasBadge = pcall(function() -- pcall so it returns the value and if there was an error
                return game:GetService("BadgeService"):UserHasBadgeAsync(v.UserId,BadgeID) -- Check if the player has the badge using RobloxAPI
            end)
            
            if success and not hasBadge then
                game:GetService("BadgeService"):AwardBadge(v.UserId, BadgeID) -- No error happened and the player does not own the badge so you can award it
            end
        end
    end
end)

I just realised that the badge was in the incorrect place. Thank you for the help.