How do I make a script which gives all players in the game a badge when a remote event is fired

Ok, so at the end of my horror game it gives a badge to all of the players. But I don’t know how to do that. I’ve tried following tutorials but all of them are either for touching a part or welcoming a player. I would like to know if its possible to award all players a badge when when a remote event is fired. Help is appreciated

local MainService = game:GetService("BadgeService")
Event.OnServerEvent:Connect(function(Player:Player?)
	MainService:AwardBadge(Player.UserId, ID)
	for _,v in game:GetService("Players"):GetPlayers() do
		if not tostring(v):lower():match(tostring(Player):lower()) then
			MainService:AwardBadge(v.UserId, ID)
		end
	end
end)

where do i put this script
also what does the :Player? mean

It’s a server-script obviously, and :Player? is just a typecheck.

alright i did try putting it in serverscriptservice but nothing happens when the remote event is fired

did you replace ID with your badge id? and did you replcae Event with your initialized event?

image

image
what happened here? can you hover and screenshot?

local MainService = game:GetService("BadgeService")
local Event:RemoteEvent? = game:GetService("ReplicatedStorage").OtherEvent.BadgeEnd
Event.OnServerEvent:Connect(function(Player:Player?)
	for _,v in game:GetService("Players"):GetPlayers() do
		if not MainService:UserHasBadgeAsync(v.UserId, ID) then
			MainService:AwardBadge(v.UserId, ID)
		end
	end
end)


now its doing the same thing with event

just ignore it or get rid of the typechecking its strict for some reason.

idk what im doing wrong but it just wont work for me
oh well thank you very much for trying to help!

Move the script to serverscriptservice and how is the event fired?

sorry about the late reply but i found a way