Put a chat message when someone buy a gamepass roblox

Hi devs, i maid this script but it doesn’t work . So if someone can help me to fix it

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

local GamepassIds = {
    156269773,
    157482066,
    156270626,
    159552653,
    156275308,
    159679613,
    156277403,
    156287007,
    156299267,

}

local function onProductPurchaseFinished(player, productId)
    for _, gamepassId in pairs(GamepassIds) do
        if productId == gamepassId then
            local playerName = player.Name

            local function generateSystemMsg(MsgDict)
                return '<font color="#'..MsgDict["Color"]..'"><font size="'..MsgDict["FontSize"]..'"><font face="'..MsgDict["Font"]..'">'..MsgDict["Text"]..'</font></font></font>'
            end

            local chatChannel = TextChatService:GetChannel("RBXSystem")
            local randomColor = Color3.new(math.random(), math.random(), math.random())

            chatChannel:SendSystemMessage(
                generateSystemMsg({
                    Text = playerName.." has just bought a Gamepass!",
                    Font = "Gotham",
                    Color = randomColor:ToHex(),
                    FontSize = "17",
                })
            )
            break
        end
    end
end

MarketplaceService.PromptProductPurchaseFinished:Connect(onProductPurchaseFinished)

Are there any errors in console? If so, please provide a screenshot of them.

1 Like

nope , i don’t have any errors

1 Like

Try and add a breakpoint, step through the onProductPurchaseFinished method to see if it even reaches there once you’ve bought the gamepass, take note of the variable values below in the ‘Watch’ tab. You can add a breakpoint by clicking to the right of the line number (in this case, the number beside):

for _, gamepassId in pairs(GamepassIds) do

Let us know where it gets to, this has helped me in the past when I want to know where something goes wrong. :slight_smile:

EDIT: Forgot to mention which options you have, from the top of my head:

  • You have ‘Step Into’ which if you’re calling a method, you can step into it and debug line-by-line within that method (you’ll get it when you try it).
  • You have ‘Step Over’ which just skips to the next line within the method you’re currently in, you’ll be using this most of the time.
  • You have ‘Step Out’ which steps out of the function you’re in (this is usually used when you use ‘Step Into’ and want to leave the method you’ve stepped into early back to the method that called it).
1 Like

There is a way but you can’t control the color, font etc

1 Like