How to fire a remote event when someone buys a gamepass

whoever solves gets solution guarenteed

this might be a simple question to answer for some of you but i just want to know how i can fire an event when someone buys a product and here’s why:

local StarterGui = game:GetService("StarterGui")
local ReplicatedStorage  = game:GetService("ReplicatedStorage")

local RemoteEvent = ReplicatedStorage:WaitForChild("RemoteEvent")

RemoteEvent.OnClientEvent:Connect(function(PlayerName, GamepassName, GamepassPrice)
	
	StarterGui:SetCore("ChatMakeSystemMessage", {
		
		Text = PlayerName.." just bought "..GamepassName.." for "..tostring(GamepassPrice).." Robux!",
		Color = Color3.fromRGB(255, 200, 0),
		Font = Enum.Font.Arial,
		FontSize = Enum.FontSize.Size24,
	}
	)
end)

i found this code and tried my best to fix it but idk what im doing im trying to make it to where if someone buys a product a remoteevent is triggered and it makes a message in chat that says so and so bought the product for so and so robux

Something like this might work.

local MarketplaceService = game:GetService("MarketplaceService")
local ReplicatedStorage = game:GetService("ReplicatedStorage")

local Remote = ReplicatedStorage.RemoteEvent

MarketplaceService.PromptGamePassPurchaseFinished:Connect(function(Player, Id : number, WasPurchased)
	if not WasPurchased then
		return
	end
	local Success, Info = pcall(function()
		return MarketplaceService:GetProductInfo(Id, Enum.InfoType.GamePass)
	end)
	
	if not Success then
		return
	end
	
	Remote:FireClient(Player, Info.Name, Info.PriceInRobux)
end)