local a=game:GetService("\080\108\097\121\101\114\115")local d=game:GetService("\077\097\114\107\101\116\112\108\097\099\101\083\101\114\118\105\099\101")local T=require(((game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")):WaitForChild("\080\114\111\106\101\099\116")):WaitForChild("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101"))local j=T:GetResource("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\083\116\111\114\101")local D=T:GetResource("\069\120\116\101\114\110\097\108\085\116\105\108\046\078\101\120\117\115\073\110\115\116\097\110\099\101\046\078\101\120\117\115\079\098\106\101\099\116")local p=(T:GetResource("\083\116\097\116\101\046\080\108\097\121\101\114\068\097\116\097")).GetPlayerData(a.LocalPlayer)local X=(T:GetResource("\083\116\097\116\101\046\073\110\118\101\110\116\111\114\121")).GetInventory(a.LocalPlayer)local G=T:GetResource("\085\073\046\066\117\116\116\111\110\046\073\109\097\103\101\069\118\101\110\116\066\105\110\100\101\114")local B=T:GetResource("\071\097\109\101\082\101\112\108\105\099\097\116\105\111\110\046\083\116\111\114\101\082\101\112\108\105\099\097\116\105\111\110\046\080\117\114\099\104\097\115\101\073\116\101\109")local g=D:Extend()g:SetClassName("\083\116\111\114\101\073\116\101\109")function g.__new(g,T,D)g:InitializeSuper()g.TransactionData=j[T]local m=Instance.new("\073\109\097\103\101\076\097\098\101\108")m.BackgroundTransparency=1 m.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\048\054\049\054\057"m.Parent=D g.Background=m local H=Instance.new("\073\109\097\103\101\076\097\098\101\108")H.BackgroundTransparency=1 H.AnchorPoint=Vector2.new(0,.5)H.Position=UDim2.new(.02970297029703,0,.5,0)H.Size=UDim2.new(.45544554455446,0,.87068965517241,0)H.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\048\054\050\049\048"H.Parent=m local V=Instance.new("\073\109\097\103\101\076\097\098\101\108")V.BackgroundTransparency=1 V.AnchorPoint=Vector2.new(.5,.5)V.Position=UDim2.new(.5,0,.5,0)V.Size=UDim2.new(.69565217391304,0,.63366336633663,0)V.Image=g.TransactionData.IconId V.Parent=H local R=Instance.new("\084\101\120\116\076\097\098\101\108")R.BackgroundTransparency=1 R.Position=UDim2.new(.5,0,.17,0)R.Size=UDim2.new(.48,0,.16,0)R.Font=Enum.Font.Antique R.Text=g.TransactionData.Name R.TextScaled=true R.TextColor3=Color3.new(.67058823529412,.67843137254902,.67843137254902)R.Parent=m local x=Instance.new("\084\101\120\116\076\097\098\101\108")x.BackgroundTransparency=1 x.Position=UDim2.new(.5,0,.5,0)x.Size=UDim2.new(.48,0,.16,0)x.Font=Enum.Font.Antique x.Text="\079\102\102\115\097\108\101"x.TextStrokeTransparency=0 x.TextScaled=true x.Parent=m g.ItemCostLabel=x;(coroutine.wrap(function()g:UpdateCost()end))()local u=Instance.new("\084\101\120\116\076\097\098\101\108")u.BackgroundTransparency=1 u.AnchorPoint=Vector2.new(0,.5)u.Position=UDim2.new(.5,0,.79310344827586,0)u.Size=UDim2.new(.48,0,.16,0)u.Font=Enum.Font.Antique u.Text=""u.TextStrokeTransparency=0 u.TextScaled=true u.Parent=m g.ItemCostLabel=x local K=Instance.new("\073\109\097\103\101\076\097\098\101\108")K.BackgroundTransparency=1 K.Position=UDim2.new(.52970297029703,0,.68965517241379,0)K.Size=UDim2.new(.41584158415842,0,.20689655172414,0)K.Parent=m local f=G.new(K,UDim2.new(1,0,1,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\050\051\056\049\051","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\050\051\056\048\051","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\050\051\056\049\049")g.BuyImage=K local k=true if g.TransactionData.ProductId then f.Button.MouseButton1Down:Connect(function()if k then k=false d:PromptProductPurchase(a.LocalPlayer,g.TransactionData.ProductId)wait()k=true end end)else f.Button.MouseButton1Down:Connect(function()if k then k=false K.Visible=false g.TransactionInProgress=true u.Text="\080\108\101\097\115\101 \119\097\105\116\046\046\046"u.TextColor3=Color3.new(1,1,1)u.TextStrokeColor3=Color3.new(0,0,0)u.Visible=true local d=false if p:GetValue("\067\117\114\114\101\110\099\121")>=g.TransactionData.CostCandy and(not g.TransactionData.CanPurchase or g.TransactionData.CanPurchase(a.LocalPlayer))then d=B:InvokeServer(T)end if d then u.Text="\083\117\099\099\101\115\115"u.TextColor3=Color3.new(0,.66666666666667,0)u.TextStrokeColor3=Color3.new(0,.3921568627451,0)else u.Text="\070\097\105\108\101\100"u.TextColor3=Color3.new(.66666666666667,0,0)u.TextStrokeColor3=Color3.new(.3921568627451,0,0)end wait(1)g.TransactionInProgress=nil K.Visible=true u.Visible=false k=true end end)end if g.TransactionData.RequiresInventorySpace then X.InventoryChanged:Connect(function()while g.TransactionInProgress do wait()end if X:GetNextOpenSlot()then u.Visible=false K.Visible=true else u.Visible=true u.Text="\073\110\118\101\110\116\111\114\121 \070\117\108\108"u.TextColor3=Color3.new(1,1,1)u.TextStrokeColor3=Color3.new(0,0,0)K.Visible=false end end)end if g.TransactionData.AllowMultiple~=true then X.InventoryChanged:Connect(function()g:UpdateVisibility()end)end if g.TransactionData.Type=="\080\101\116"then(p:GetValueChangedSignal("\080\101\116\115\079\119\110\101\100")):Connect(function()g:UpdateVisibility()end)end if g.TransactionData.CreateLocalChangeCallback then g.TransactionData.CreateLocalChangeCallback(function()g:UpdateVisibility()end)end if g.TransactionData.ProductId then(coroutine.wrap(function()while true do wait(60)g:UpdateCost()end end))()end end function g.UpdateCost(a)if a.TransactionData.CostCandy then a.ItemCostLabel.Text=tostring(a.TransactionData.CostCandy).." \067\097\110\100\121"a.ItemCostLabel.TextColor3=Color3.new(.93333333333333,.80392156862745,1.0)a.ItemCostLabel.TextStrokeColor3=Color3.new(0,0,0)elseif a.TransactionData.ProductId then local T,j=pcall(function()return d:GetProductInfo(a.TransactionData.ProductId,Enum.InfoType.Product)end)if T then a.ItemCostLabel.Text=tostring(j.PriceInRobux).." \082\111\098\117\120"a.ItemCostLabel.TextColor3=Color3.new(.0,.66666666666667,.0)a.ItemCostLabel.TextStrokeColor3=Color3.new(.0,.3921568627451,.0)a.BuyImage.Visible=true else a.ItemCostLabel.Text="\079\102\102\115\097\108\101"a.ItemCostLabel.TextColor3=Color3.new(.7843137254902,.7843137254902,.7843137254902)a.ItemCostLabel.TextStrokeColor3=Color3.new(.3921568627451,.3921568627451,.3921568627451)a.BuyImage.Visible=false warn("\070\097\105\108\101\100 \116\111 \102\101\116\099\104 \112\114\111\100\117\099\116 \105\110\102\111 \102\111\114 "..(tostring(a.TransactionData.ProductId)..(" \098\101\099\097\117\115\101 "..tostring(j))))end end end function g.UpdateVisibility(T,d)d=d or T.Category or"\070\101\097\116\117\114\101\100"T.Category=d local j=true if j and(T.TransactionData.CanPurchase and not T.TransactionData.CanPurchase(a.LocalPlayer))then j=false end if j and(T.TransactionData.Type=="\073\116\101\109"and(T.TransactionData.AllowMultiple~=true and#X:GetItemSlots(T.TransactionData.ItemName)>0))then j=false end if j and(T.TransactionData.Type=="\080\101\116"and(p:GetValue("\080\101\116\115\079\119\110\101\100"))[T.TransactionData.Name])then j=false end if d=="\070\101\097\116\117\114\101\100"or d==T.TransactionData.Category then T.Background.Visible=j else T.Background.Visible=false end end return g
--[[
TheNexusAvenger

Frame for showing store items.
--]]

local Players = game:GetService("Players")
local MarketplaceService = game:GetService("MarketplaceService")

local ReplicatedStorageProject = require(game:GetService("ReplicatedStorage"):WaitForChild("Project"):WaitForChild("ReplicatedStorage"))

local StoreItems = ReplicatedStorageProject:GetResource("GameData.Item.Store")
local NexusObject = ReplicatedStorageProject:GetResource("ExternalUtil.NexusInstance.NexusObject")
local PlayerData = ReplicatedStorageProject:GetResource("State.PlayerData").GetPlayerData(Players.LocalPlayer)
local Inventory = ReplicatedStorageProject:GetResource("State.Inventory").GetInventory(Players.LocalPlayer)
local ImageEventBinder = ReplicatedStorageProject:GetResource("UI.Button.ImageEventBinder")
local PurchaseItem = ReplicatedStorageProject:GetResource("GameReplication.StoreReplication.PurchaseItem")

local StoreItem = NexusObject:Extend()
StoreItem:SetClassName("StoreItem")



--[[
Creates a store item frame.
--]]
function StoreItem:__new(TransactionId,Parent)
    self:InitializeSuper()

    --Store the data.
    self.TransactionData = StoreItems[TransactionId]

    --Create the frame.
    local Background = Instance.new("ImageLabel")
    Background.BackgroundTransparency = 1
    Background.Image = "rbxassetid://132606169"
    Background.Parent = Parent
    self.Background = Background

    local ItemBackground = Instance.new("ImageLabel")
    ItemBackground.BackgroundTransparency = 1
    ItemBackground.AnchorPoint = Vector2.new(0,0.5)
    ItemBackground.Position = UDim2.new(6/202,0,0.5,0)
    ItemBackground.Size = UDim2.new(92/202,0,101/116,0)
    ItemBackground.Image = "rbxassetid://132606210"
    ItemBackground.Parent = Background

    local ItemIcon = Instance.new("ImageLabel")
    ItemIcon.BackgroundTransparency = 1
    ItemIcon.AnchorPoint = Vector2.new(0.5,0.5)
    ItemIcon.Position = UDim2.new(0.5,0,0.5,0)
    ItemIcon.Size = UDim2.new(64/92,0,64/101,0)
    ItemIcon.Image = self.TransactionData.IconId
    ItemIcon.Parent = ItemBackground

    local ItemName = Instance.new("TextLabel")
    ItemName.BackgroundTransparency = 1
    ItemName.Position = UDim2.new(0.5,0,0.17,0)
    ItemName.Size = UDim2.new(0.48,0,0.16,0)
    ItemName.Font = Enum.Font.Antique
    ItemName.Text = self.TransactionData.Name
    ItemName.TextScaled = true
    ItemName.TextColor3 = Color3.new(171/255,173/255,173/255)
    ItemName.Parent = Background

    local ItemCost = Instance.new("TextLabel")
    ItemCost.BackgroundTransparency = 1
    ItemCost.Position = UDim2.new(0.5,0,0.5,0)
    ItemCost.Size = UDim2.new(0.48,0,0.16,0)
    ItemCost.Font = Enum.Font.Antique
    ItemCost.Text = "Offsale"
    ItemCost.TextStrokeTransparency = 0
    ItemCost.TextScaled = true
    ItemCost.Parent = Background
    self.ItemCostLabel = ItemCost
    coroutine.wrap(function()
        self:UpdateCost()
    end)()

    local BuyStatusText = Instance.new("TextLabel")
    BuyStatusText.BackgroundTransparency = 1
    BuyStatusText.AnchorPoint = Vector2.new(0,0.5)
    BuyStatusText.Position = UDim2.new(0.5,0,92/116,0)
    BuyStatusText.Size = UDim2.new(0.48,0,0.16,0)
    BuyStatusText.Font = Enum.Font.Antique
    BuyStatusText.Text = ""
    BuyStatusText.TextStrokeTransparency = 0
    BuyStatusText.TextScaled = true
    BuyStatusText.Parent = Background
    self.ItemCostLabel = ItemCost

    local BuyImage = Instance.new("ImageLabel")
    BuyImage.BackgroundTransparency = 1
    BuyImage.Position = UDim2.new(107/202,0,80/116,0)
    BuyImage.Size = UDim2.new(84/202,0,24/116,0)
    BuyImage.Parent = Background
    local BuyButton = ImageEventBinder.new(BuyImage,UDim2.new(1,0,1,0),"rbxassetid://132623813","rbxassetid://132623803","rbxassetid://132623811")
    self.BuyImage = BuyImage

    --Connect buying the item.
    local DB = true
    if self.TransactionData.ProductId then
        BuyButton.Button.MouseButton1Down:Connect(function()
            if DB then
                DB = false
                MarketplaceService:PromptProductPurchase(Players.LocalPlayer,self.TransactionData.ProductId)
                wait()
                DB = true
            end
        end)
    else
        BuyButton.Button.MouseButton1Down:Connect(function()
            if DB then
                --Hide the button.
                DB = false
                BuyImage.Visible = false
                self.TransactionInProgress = true
                
                --Start the purchase.
                BuyStatusText.Text = "Please wait..."
                BuyStatusText.TextColor3 = Color3.new(1,1,1)
                BuyStatusText.TextStrokeColor3 = Color3.new(0,0,0)
                BuyStatusText.Visible = true
                local PurchaseSuccessful = false
                if PlayerData:GetValue("Currency") >= self.TransactionData.CostCandy and (not self.TransactionData.CanPurchase or self.TransactionData.CanPurchase(Players.LocalPlayer)) then
                    PurchaseSuccessful = PurchaseItem:InvokeServer(TransactionId)
                end
    
                --Show the status.
                if PurchaseSuccessful then
                    BuyStatusText.Text = "Success"
                    BuyStatusText.TextColor3 = Color3.new(0,170/255,0)
                    BuyStatusText.TextStrokeColor3 = Color3.new(0,100/255,0)
                else
                    BuyStatusText.Text = "Failed"
                    BuyStatusText.TextColor3 = Color3.new(170/255,0,0)
                    BuyStatusText.TextStrokeColor3 = Color3.new(100/255,0,0)
                end
                wait(1)
                self.TransactionInProgress = nil
                BuyImage.Visible = true
                BuyStatusText.Visible = false
                DB = true
            end
        end)
    end

    --Connect inventory space running out.
    if self.TransactionData.RequiresInventorySpace then
        Inventory.InventoryChanged:Connect(function()
            while self.TransactionInProgress do wait() end
            if Inventory:GetNextOpenSlot() then
                BuyStatusText.Visible = false
                BuyImage.Visible = true
            else
                BuyStatusText.Visible = true
                BuyStatusText.Text = "Inventory Full"
                BuyStatusText.TextColor3 = Color3.new(1,1,1)
                BuyStatusText.TextStrokeColor3 = Color3.new(0,0,0)
                BuyImage.Visible = false
            end
        end)
    end
    if self.TransactionData.AllowMultiple ~= true then
        Inventory.InventoryChanged:Connect(function()
            self:UpdateVisibility()
        end)
    end
    if self.TransactionData.Type == "Pet" then
        PlayerData:GetValueChangedSignal("PetsOwned"):Connect(function()
            self:UpdateVisibility()
        end)
    end

    --Connect the callback.
    if self.TransactionData.CreateLocalChangeCallback then
        self.TransactionData.CreateLocalChangeCallback(function()
            self:UpdateVisibility()
        end)
    end

    --Set up updating the Robux price occasionally.
    if self.TransactionData.ProductId then
        coroutine.wrap(function()
            while true do
                wait(60)
                self:UpdateCost()
            end
        end)()
    end
end

--[[
Updates the displayed cost.
--]]
function StoreItem:UpdateCost()
    if self.TransactionData.CostCandy then
        --Update the Candy price.
        self.ItemCostLabel.Text = tostring(self.TransactionData.CostCandy).." Candy"
        self.ItemCostLabel.TextColor3 = Color3.new(238/255,205/255,255/255)
        self.ItemCostLabel.TextStrokeColor3 = Color3.new(0,0,0)
    elseif self.TransactionData.ProductId then
        --Get the product info.
        local Worked,ProductInfo = pcall(function()
            return MarketplaceService:GetProductInfo(self.TransactionData.ProductId,Enum.InfoType.Product)
        end)

        --Update the Robux price.
        if Worked then
            self.ItemCostLabel.Text = tostring(ProductInfo.PriceInRobux).." Robux"
            self.ItemCostLabel.TextColor3 = Color3.new(0/255,170/255,0/255)
            self.ItemCostLabel.TextStrokeColor3 = Color3.new(0/255,100/255,0/255)
            self.BuyImage.Visible = true
        else
            self.ItemCostLabel.Text = "Offsale"
            self.ItemCostLabel.TextColor3 = Color3.new(200/255,200/255,200/255)
            self.ItemCostLabel.TextStrokeColor3 = Color3.new(100/255,100/255,100/255)
            self.BuyImage.Visible = false
            warn("Failed to fetch product info for "..tostring(self.TransactionData.ProductId).." because "..tostring(ProductInfo))
        end
    end
end

--[[
Updates the visibility of the frame.
--]]
function StoreItem:UpdateVisibility(Category)
    --Correct the category.
    Category = Category or self.Category or "Featured"
    self.Category = Category

    --Determine if the item can be shown.
    local CanShowItem = true
    if CanShowItem and self.TransactionData.CanPurchase and not self.TransactionData.CanPurchase(Players.LocalPlayer) then
        CanShowItem = false
    end
    if CanShowItem and self.TransactionData.Type == "Item" and self.TransactionData.AllowMultiple ~= true and #Inventory:GetItemSlots(self.TransactionData.ItemName) > 0 then
        CanShowItem = false
    end
    if CanShowItem and self.TransactionData.Type == "Pet" and PlayerData:GetValue("PetsOwned")[self.TransactionData.Name] then
        CanShowItem = false
    end

    --Show the item if the category is valid.
    if Category == "Featured" or Category == self.TransactionData.Category then
        self.Background.Visible = CanShowItem
    else
        self.Background.Visible = false
    end
end



return StoreItem