Is this a right way to give a badge to a player when the event is triggered?

Hello guys, I want to know if this is a right way to give a badge or not because I tried searching up many instructions as possible but most of them doesn’t help. I did try this in an actual roblox game in my game and see if the boss is killed, the remoteevent trigger to this localscript below which this is in the StarterPlayer >> StarterPlayerScripts and I didn’t actually got a badge because of the UserId error thingy? if I’m wrong, will you guys correct it for me?

local Event = game.ReplicatedStorage.Events:WaitForChild("BossDefeated")
local SansTalk = game.Workspace.SansTalk
local teleportService = game:GetService("TeleportService")
local PlaceID = 6319191217
local BadgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")

BadgeId = 2124681279

local function typewrite(object,text,length)
	for i = 1,#text,1 do
		object.Text = string.sub(text,1,i)
		wait(length)
	end
end


game.ReplicatedStorage.Events.BossDefeated.OnClientEvent:Connect(function(player)
	BadgeService:AwardBadge(player.UserId, BadgeId) -- is this the right way to give player badge?
	script.Parent.Parent.PlayerGui.VictoryMessage.Enabled = true
	wait(4)
	SansTalk:Play()
	typewrite(script.Parent.Parent.PlayerGui.VictoryMessage:WaitForChild("TextLabel"),"Okay, Fine.     You defeated me!",0.05)
	SansTalk:Stop()
	wait(1)
	SansTalk:Play()
	typewrite(script.Parent.Parent.PlayerGui.VictoryMessage:WaitForChild("TextLabel"),"I did buy mass amounts of iPads just so that",0.01)
	SansTalk:Stop()
	wait(1)
	SansTalk:Play()
	typewrite(script.Parent.Parent.PlayerGui.VictoryMessage:WaitForChild("TextLabel"),"I can use these as my alt accounts to pretend to be my friends.",0.01)
	SansTalk:Stop()

Megalovania Intensifies Turns out, you actually need to Award the Badge on the Server-Side & not on the Client Side so I think you could potentially check when the boss dies with a Humanoid Died Event? Or so that it’s not visible to the Workspace

If i want to award the badge on the server side to all players? it needs to say player.UserId and then the BadgeId.

local debouncetwo = false
local BadgeService = game:GetService("BadgeService")
local PlayerService = game:GetService("Players")

BadgeId = 2124681279

while debouncetwo == false do
	wait(0.01)
	if game.Workspace.Redacted.Humanoid.Health < 1 then
		game.ReplicatedStorage.Events.BossDefeated:FireAllClients(game.Players.LocalPlayer)
		BadgeService:AwardBadge(player.UserId, BadgeId)
		debouncetwo = true
	end
end

-- NOTE: This is how when the boss is killed, the badge is given to all players
-- I also put redacted on the npc because my game might have story side so no spoilers!

also ignore the script above since I can’t put 2 separate scripts so this is the script below:
@Jackscarlett is it like this:

local debouncetwo = false
local BadgeService = game:GetService("BadgeService")

BadgeId = 2124681279

while debouncetwo == false do
	wait(0.01)
	if game.Workspace.Redacted.Humanoid.Health < 1 then
		game.ReplicatedStorage.Events.BossDefeated:FireAllClients(game.Players.LocalPlayer)
		for _, player in pairs(game.Players:GetPlayers()) do
			BadgeService:AwardBadge(player.UserId, BadgeId)
		end
		debouncetwo = true
	end
end

You can put all the players through a table I believe with this, you don’t need to use a RemoteEvent:

for _, player in pairs(game.Players:GetPlayers()) do
    BadgeService:AwardBadge(player.UserId, BadgeId)
end