Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Can someone help fix GUI donation button? When clicked, no errors in output, but nothing happens.

Hi, I am working on a game and I want there to be a donate button in the GUI. Here is the script:

local productId = 978564492 
local donateButton = game.StarterGui.DonateGUI.DonateButton
local function donate(player)
game:GetService("MarketplaceService"):PromptProductPurchase(player,productId) 
game.StarterGui.DonateGUI.DonateButton.MouseButton1Click:Connect(donate)
end

This script is located in game.StarterGui.DonateGUI.DonateButton.DonateScript. It is a LocalScript. I do not get any errors in the output, but when test the game, I click the button and nothing happens.

Here is an image of where the script and button is located: https://photos.app.goo.gl/rUcJvQN71Y2RWa4t7

I would appreciate it if somebody could help. Thanks

1 answer

✓ Accepted answer

StarterGui is a placeholder container on the Server. It merely replicates the UI content into the Player upon connection. The actual authentic location of the User Interface is local to the Client, in it's own container named PlayerGui. Think of this relationship as StarterPack and Backpack. This is sensible as everyone has their own interface, simply accessing one universal folder would affect everyone.

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

local Player = Players.LocalPlayer
local PlayerGui = Player:WaitForChild("PlayerGui")
local DonateGui = PlayerGui:WaitForChild("DonateGui")
local DonateButton = DonateGui:WaitForChild("DonateButton")

local ProductId = 978564492 

DonateButton.MouseButton1Click:Connect(function()
	MarketplaceService:PromptProductPurchase(Player, ProductId) 
end)

If this helped, don't forget to accept this answer!

1 comment

0

Thanks. I actually got it to work by replacing the last line with script.parent.MouseButton1Click:Connect(function() donate(game.Players.LocalPlayer) end) and replacing all instances of game.StarterGui.DonateGUI.DonateButton with script.parent

This discussion is preserved as it was. New answers, comments, and votes are closed.