I’m using a Gui inside a backpack item that uses collection service to prompt a purchase. whenever I equip the item, It does not run any of the button’s actions. When I add tags to the Player GUI version of the interface these buttons work as expected.
local Mp = game:GetService("MarketplaceService")
local Players = game:GetService("Players")
local cs = game:GetService("CollectionService")
local rs = game:GetService("ReplicatedStorage")
local button = script.Parent
local plr = Players.LocalPlayer
--print(button.Name .." has a script running")
--button.MouseButton1Down:Connect(function(...)
-- print(button.Name .." has a script running")
-- print("prompted")
--end)
local PurchaseButton = {}
PurchaseButton.__index = PurchaseButton
PurchaseButton.TAG_NAME = "Purchase Button"
function PurchaseButton.new(button)
local self = {}
setmetatable(self, PurchaseButton)
self.button = button
self.debounce = false
local NormalColor = button.BackgroundColor3
button.MouseEnter:Connect(function()
button.BackgroundColor3 = Color3.new(0, 1, 1)
-- moreInfo.Visible = true
end)
button.MouseLeave:Connect(function()
button.BackgroundColor3 = NormalColor
-- moreInfo.Visible = false
end)
self.ActivatedCon = button.Activated:Connect(function(...)
self:PurchasePrompt()
end)
--print("Initialized button: " .. button:GetFullName())
return self
end
function PurchaseButton:PurchasePrompt()
if plr then
local btype = self.button:GetAttribute("Type")
if btype == "Gamepass" then
Mp:PromptGamePassPurchase(plr, self.button:GetAttribute("AssetId"))
elseif btype == "Shirt" then
Mp:PromptPurchase(plr,self.button:GetAttribute("AssetId") )
end
end
end
function PurchaseButton:Cleanup()
self.ActivatedCon:disconnect()
self.ActivatedCon = nil
end
local purchaseButtons = {}
local ButtonAddedSignal = cs:GetInstanceAddedSignal(PurchaseButton.TAG_NAME)
local ButtonRemovedSignal = cs:GetInstanceRemovedSignal(PurchaseButton.TAG_NAME)
local function onButtonAdded(button)
print(button:GetFullName())
if button:IsA("TextButton") then
purchaseButtons[button] = PurchaseButton.new(button)
end
end
local function onButtonRemoved(button)
if purchaseButtons[button] then
print(button:GetFullName().."removed")
purchaseButtons[button]:Cleanup()
purchaseButtons[button] = nil
end
end
for _, inst in pairs(cs:GetTagged(PurchaseButton.TAG_NAME)) do
onButtonAdded(inst)
end
ButtonAddedSignal:Connect(onButtonAdded)
ButtonRemovedSignal:Connect(onButtonRemoved)