Donation surface ui not working

Okay so I have a donation board set up and this script worked in the normal screen gui but not for surface gui :

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local developerProductId = 3463682241

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(player, developerProductId)
end)

-- Server script!
--3rd party sales enabled!

Put the SurfaceGui in StarterGui and just set the Adornee to the part you originally had it parented under

No that didn’t work here’s the script i used :

local MarketplaceService = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local player = Players.LocalPlayer

local developerProductId = 3463682241

script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(player, developerProductId)
end)

clone = script.Parent.Parent:Clone()
clone.Parent = game.Workspace.Donation["Donation 1"]

--It did show on the Part

Im assuming that Clone is the surfacegui? Because if so then try replacing

clone.Parent = game.Workspace.Donation["Donation 1"]

with

clone.Parent = player.PlayerGui
clone.Adornee = game.Workspace.Donation["Donation 1"]

No that didnt work either i think its the main script shuch as

Can you check the developer console or output?
(check dev console by saying /console in chat or opening it from the roblox menu)

There’s nothing in the console to do with the Donation ui

Hm
Is this a localscript inside the button in the surfacegui which should be under startergui

localscript WILL NOT WORK in the surface GUI because it’s outside of folders which client scripts have access to. You need to rewrite this completely, and if you want to keep the surface GUI, then you’re gonna have to break down this local script into a server-sided script and a client-sided script with a remote event connecting both. Also, if you’re going to use a remote event to connect both, you should also secure it, to make sure exploiters don’t exploit it for their own benefit and your dismay.

You can immediately tell that it’s a LocalScript object by this line of code:

you can’t get or reference players like this in a serverscript

you should use this instead

Players.PlayerAdded:Connect(function(player)
--[[the parameters gives you the player who joined in the server, very similar to Players.LocalPlayer but in a server script]]--

read the comment in the script and wrap PlayerAdded event around MouseButton1Click event

like this

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

local developerProductId = 3463682241

Players.PlayerAdded:Connect(function(player)
  script.Parent.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(player, developerProductId)
    end)
end)

-- Server script!
--3rd party sales enabled!

if it still doesnt work please check out the documentation further
https://create.roblox.com/docs/reference/engine/classes/MarketplaceService

in the original script’s comments it was mentioned that it was in a server script

-- Server script!

But its not my guy

But my guy

You can not get the local player from a server script

As @Sindious said, you cannot access “local player” from the server, it just doesn’t make any sense.

What you seem to be trying to do is prompting the player’s who clicked on the button with the purchase. To do so, you can get that player in the MouseButton1Click’s event:

script.Parent.MouseButton1Click:Connect(function(player: Player)

and completely remove the local player = Players.LocalPlayer, that only works on the client, not on the server!

Huh, didn’t notice that, that changes everything, the issue isn’t that it’s a localscript in a place where it won’t execute, the problem is that it’s using commands only available on the localscript while being a server-sided script, among other problems.