SurfaceGui Buttons won't Work

  1. I want to fix my SurfaceGui Buttons (for a donation board), because they don’t work.

  2. When I click a button, it won’t work.

    Locations Image

    image

    An error didn’t popup and I tried using print statements (didn’t work)

Server Script in Workspace (Handles Buttons)
local buttonlist = game:GetService("Workspace"):WaitForChild("Lobby"):WaitForChild("DonationBoardPart"):WaitForChild("DonationBoardGui")
local marketplaceSV = game:GetService("MarketplaceService")

local Buttons = {
	[1] = {
		1153796205, 
		"5RobuxButton"
	},
	[2] = {
		1153796328, 
		"10RobuxButton"
	},
	[3] = {
		1153796501,
		"25RobuxButton"
	},
	[4] = {
		1153796703,
		"50RobuxButton"
	},
	[5] = {
		1153797121,
		"100RobuxButton"
	},
	[6] = {
		1153797239,
		"250RobuxButton"
	},
	[7] = {
		1153797321,
		"500RobuxButton"
	},
	[8] = {
		1153797396,
		"1000RobuxButton"
	}
}

local function Buy(Player)
	local Num = nil
	for i,v in pairs(Buttons) do
		if Num == nil then Num = i continue end
		if Num < i then
			Num = i
		end
	end
	for i = Num, 1, -1 do
		if Buttons[i] == nil then continue end
		for d,k in pairs(buttonlist:GetChildren()) do
			if k:isA("GuiButton") then
				k.MouseButton1Down:Connect(function()
					if string.lower(k.Name) == string.lower(Buttons[i][2]) then
						marketplaceSV:PromptProductPurchase(Player,Buttons[i][1])
					end
				end)
				return
			end
		end
	end
end	


game.Players.PlayerAdded:Connect(function(Player)
	Buy(Player)
end)	

If you have any idea of how to fix this, then please tell me!

Parent the SurfaceGui to StarterGui and make the Adornee property the object. You’d have to reconfigure your script however

Should this be the update to the script?

local buttonlist = game.StarterGui:WaitForChild("DonationBoardGui")

No, everything in StarterGui gets replicated to PlayerGui. You would have to do this:

game.Players.PlayerAdded:Connect(function(player)
   local playerGui = player:WaitForChild("PlayerGui"):WaitForChild("DonationBoardGui")
   -- do stuff
end)
1 Like

The DonationBoardGui goes inside the player instead of PlayerGui?

My mistake, I missed PlayerGui

local playerGui = player:WaitForChild("PlayerGui"):WaitForChild("DonationBoardGui")

I had the exact same problem. Set the Adornee of the SurfaceGui to the donation board (part) and then parent the SurfaceGui to StarterGui.

after doing what @THECOOLGENERATOR says, it would be better to put a local script in the surface gui with the following code:

local marketplaceSV = game:GetService("MarketplaceService")

local Ids = {
	["5RobuxButton"] = 1153796205,
	["10RobuxButton"] = 1153796328, 
	["25RobuxButton"] = 1153796501,
	["50RobuxButton"] = 1153796703,
	["100RobuxButton"] = 1153797121,
	["250RobuxButton"] = 1153797239,
	["500RobuxButton"] = 1153797321,
	["1000RobuxButton"] = 1153797396
}

for i, v in pairs(script.Parent:GetChildren()) do
    if v:IsA("GuiButton") then
        v.MouseButton1Down:Connect(function()
            -- prompt the purchase from the client or add a remote event to prompt it from the server

            marketplaceSV:PromptProductPurchase(Ids[v.Name]) --maybe you need to add game:GetService("Players").LocalPlayer as first argument
        end
    end
end

Edit: i dont know if you can access the buttons from the server…

I think you can access text button clicks from the server, so maybe it’ll work with SurfaceGui buttons?

maybe if you use game.Players.Player.SurfaceGui as a directory for each individual player, however, almost nothing changes if you do it directly from a local script