How would I use "PlayerHasBadgeAysnc()"

In my game I got a idea to make it if a player has a badge destroy a script I have done some research and I think I need to use PlayerHasBadgeAysnc()
If someone could put this in a script to do a random thing it would help.

So tell me the id of the badge, and what you want to do with it

This is one of my scripts that checks for a pass on loading.
I use it in ServerScriptService and it is not a Local script.

local Players = game:GetService("Players")
local MarketPlaceService = game:GetService("MarketplaceService")
local gamepassID = 1000000 --> The ID of your Badge.

function Spawned(player)
	wait(1.1) local HasGamepass = false
	local success, message = pcall(function()
		HasGamepass = MarketPlaceService:UserOwnsGamePassAsync(player.userId, gamepassID)
	end)

	if not success then
		warn("Checking Gamepass "..tostring(message))
		return
	end

	if HasGamepass == true then
		
		--> Has pass do stuff!
		
	end
end

game.Players.PlayerAdded:Connect(function(player)
	player.CharacterAdded:Connect(function()
		Spawned(player)
	end)
end)

You can actually use BadgeService for that.

local BadgeService = game:GetService("BadgeService")
local Players = game:GetService("Players")

local BadgeID = 00000000 -- The ID of your Badge.

Players.PlayerAdded:Connect(function()
     local success, hasBadge = pcall(function()
		return BadgeService:UserHasBadgeAsync(player.UserId, BadgeID)
	end)

     if hasBadge then
		workspace.MyScript:Destroy() -- Path to your script. If you want to destroy the script only for the player use a Local Script. If you want to destroy the script to the whole server use a Server Script.
	end
end)

At the moment I don’t need it to do anything I just want to learn how I would add it to my scripts.

PlayerHasBadgeAsync would be mostly good for if statements!

Example

local BadgeService = game:GetService("BadgeService")
local ID = 0000000

local function CheckBadgeOwnership(Player)
    if BadgeService:PlayerHasBadgeAsync(Player.UserId, ID) then
        print("Player has Badge: "..ID)

        -- Code
    end
end

CheckBadgeOwnership()