Need help with Prompting UGC Limited purchase

I used Roblox AI Assistant to script a simple purchase prompt for when a player meets a specific requirement on their leaderstats. I’ve tested this various different times & still havent managed to get it to work. I would love some help! (script resides in ServerScriptService btw)

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

local YENS_REQUIREMENT = 100 -- Change this to your desired requirement

local function promptPurchase(player)
    local yens = player.leaderstats.Yens.Value
    if yens >= YENS_REQUIREMENT then
        local productId = 123456789 -- Replace with the UGC product ID
        MarketplaceService:PromptPurchase(player, productId)
    end
end

local function onPlayerAdded(player)
    player.CharacterAdded:Connect(function(character)
        promptPurchase(player)
    end)
end

Players.PlayerAdded:Connect(onPlayerAdded)

Listen to what the comment says

did that and it didnt work when testing

Did you turn this on? (Game Settings > Security)
image

Yeah, I found another script on the devforum which works flawlessly but isnt what I’m going for. So there’s definitely something wrong with the script which the AI provided.