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!
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
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’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!
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:
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.