It is already Local script
local MarketplaceService = Game:GetService("MarketplaceService")
local buyButton = game.Workspace.BuyButton.SurfaceGui.TextButton
local productId = 21248921
buyButton.MouseButton1Click:connect(function()
MarketplaceService:PromptProductPurchase(player, productId)
end)

3 comments
Also, I have -9 Because I had a really bad time on here ;c
I tried that same thing too man. :c Its something that roblox did when releasing 'MarketplaceServce', I think its Server-Sided only. :c
You didn't define the player variable that you called on line 6.