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

This Gui should work but it doesnt...?

Im trying to make a Gui that you can click on and you can buy something. It is a regular script and a Textbutton inside a ScreenGui, inside the StarterGUI. The script is...

local assetId = 27112438 --Insert any object Id

script.Parent.TextButton.MouseButton1Down:connect(function(player) --If true connect the function player
Game:GetService("MarketplaceService"):PromptPurchase(player, assetId)
end)

2 answers

✓ Accepted answer

The player is not passed as an argument when the MouseButton1Down event fires.

local assetId = 27112438 --Insert any object Id

local player = script.Parent.Parent.Parent
while not player:IsA("Player") do player = player.Parent end --Keep going up until we find the player

script.Parent.TextButton.MouseButton1Down:connect(function()
game:GetService("MarketplaceService"):PromptPurchase(player, assetId)
end)

1 comment

0

Thank you now I will continue with my project!

local bloxyColaId = 164625523--id of product or gamepass if its produt, its productid
local player = game.Players.LocalPlayer

function onClick() 
Game:GetService("MarketplaceService"):PromptPurchase(player, bloxyColaId) 
end

script.Parent.MouseButton1Click:connect(onClick)
--this goes in a local script

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