Ui Controller Doesn't Work

Hey could somebody help me with figuring out whats wrong with my script that controls donation buttons. heres the local script

local donations = {
	['Donate10'] = 1265665801,
	['Donate100'] = 1265665829,
	['Donate1000'] = 1265665853,
	['Donate10000'] = 1265665881,
	['Donate100000'] = 1265665924,
}

local screen_gui  = game.StarterGui.ScreenGui
for i, v in pairs(screen_gui:WaitForChild('Frame'):GetChildren()) do
	if v:IsA('TextButton') and string.sub(v.Name, 1, #('Donate')) == 'Donate' then
		local id = (donations[v.Name])
		if not (id) then continue end
		v.MouseButton1Click:Connect(function()
			game:GetService('MarketplaceSerice'):PromptProductPurchase(game.Players.LocalPlayer, id)
		end)
	end
end

and heres what the buttons look like
image
all help would be much appreciated

What doesn’t work about it?


It doesnt register let you buy the dev product once clicked on the button, no errors in output. Since no errors I think something is wrong with the logic

Try changing
if v:IsA(‘TextButton’) and string.sub(v.Name, 1, #(‘Donate’)) == ‘Donate’ then

to
if v:IsA(‘TextButton’) and string.sub(v.Name, 1, #(‘Donate’)) == ‘Donate’ and v.Name ~= ‘Donate’ then

to avoid having it register the “Donate” button, when I reuse the script I get an error because it can’t find the ID

1 Like

it still doesn’t register that im trying to purchase the button. Any other help? This is what the script is looking like right now

local donations = {
	['Donate10'] = 1265665801,
	['Donate100'] = 1265665829,
	['Donate1000'] = 1265665853,
	['Donate10000'] = 1265665881,
	['Donate100000'] = 1265665924,
}

local screen_gui  = game.StarterGui.ScreenGui
for i, v in pairs(screen_gui:WaitForChild('Frame'):GetChildren()) do
	if v:IsA("TextButton") and string.sub(v.Name, 1, #("Donate")) == "Donate" and v.Name ~= "Donate" then
		local id = (donations[v.Name])
		if not (id) then continue end
		v.MouseButton1Click:Connect(function()
			game:GetService('MarketplaceSerice'):PromptProductPurchase(game.Players.LocalPlayer, id)
		end)
	end
end

You must get the screenGui from the local player, not from the starterGui

local screen_gui = game.Players.LocalPlayer.PlayerGui.ScreenGui

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.