Why does donation script not work?

I was trying to make a script that would allow people to donate to me. I have a script that won’t work, but everything seems valid and no errors showed up in the output. Here is the script:

local player = game.Players.LocalPlayer
local id = "1007790822"

script.Parent.MouseClick:Connect(function()
	game.MarketplaceService:PromptProductPurchase(player, id)
end)

script.Parent.Parent.Touched:Connect(function()
	game.MarketplaceService:PromptProductPurchase(player, id)
end)
Properties of Script

Script type: LocalScript
Parent: ClickDetector
Parent of ClickDetector: Part
Disabled: False

So then, someone might be thinking, “Maybe your id is wrong…”. The id is not wrong. Proof:
7d725d816c49252ae3c88187c15c885d

Please help me try to figure out what is going wrong!

1 Like

LocalScripts won’t run in workspace or its descendants.

Use it where it’ll actually execute, such as StarterPlayerScripts and index the objects in workspace appropriately (i.e use WaitForChild if required).

This is very helpful, thanks for including that.

2 Likes

Thanks, I will try this!

30 char

1 Like

Didn’t work,
I put the following script inside of a localscript inside of starterplayerscripts:

local player = game.Players.LocalPlayer
local id = "1007790822"
game.Workspace.DonoPrompt.ClickDetector.MouseClick:Connect(function()
	game.MarketplaceService:PromptProductPurchase(player, id)
end)

game.Workspace.DonoPrompt.Touched:Connect(function()
	game.MarketplaceService:PromptProductPurchase(player, id)
end)

What’d I do wrong?

1 Like

You didn’t wait for ‘DonoPrompt’ to replicate

local player = game.Players.LocalPlayer
local id = "1007790822"

local DonoPrompt = workspace:WaitForChild("DonoPrompt", 10)

DonoPrompt.ClickDetector.MouseClick:Connect(function()
	game.MarketplaceService:PromptProductPurchase(player, id)
end)

DonoPrompt.Touched:Connect(function()
	game.MarketplaceService:PromptProductPurchase(player, id)
end)
1 Like

It works now! Thanks so much!

30 char

2 Likes