I want to fix my SurfaceGui Buttons (for a donation board), because they don’t work.
When I click a button, it won’t work.
Locations 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!
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…
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