Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

This Gui should work but it doesnt...?

Asked by
Ulysies 50
9 years ago

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

Log in to vote
1
Answered by
2eggnog 981 Moderation Voter
9 years ago

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)
0
Thank you now I will continue with my project! Ulysies 50 — 9y
Ad
Log in to vote
0
Answered by 9 years ago
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

Answer this question