local a={"\070\101\097\116\117\114\101\100";"\067\111\109\112\097\110\105\111\110\115";"\067\117\115\116\111\109\105\122\101","\085\110\108\111\099\107\097\098\108\101\115"}local d=game:GetService("\080\108\097\121\101\114\115")local T=game:GetService("\082\101\112\108\105\099\097\116\101\100\083\116\111\114\097\103\101")local j=require((T: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 D=j:GetResource("\071\097\109\101\068\097\116\097\046\073\116\101\109\046\083\116\111\114\101")local p=j: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 X=j:GetResource("\085\073\046\066\117\116\116\111\110\046\087\105\100\101\084\101\120\116\066\117\116\116\111\110\068\101\099\111\114\097\116\111\114")local G=j:GetResource("\085\073\046\065\115\112\101\099\116\082\097\116\105\111\083\119\105\116\099\104\101\114")local B=j:GetResource("\083\116\097\116\101\046\068\105\115\112\108\097\121\079\114\100\101\114\067\111\110\116\114\111\108\108\101\114")local g=(j:GetResource("\083\116\097\116\101\046\080\108\097\121\101\114\068\097\116\097")).GetPlayerData(d.LocalPlayer)local m=require(script:WaitForChild("\083\116\111\114\101\073\116\101\109"))local H=true local V="\070\101\097\116\117\114\101\100"local R={}local x,u local function K()for a,d in pairs(R)do d:UpdateVisibility(V)end end local function f()local a=x.AbsoluteSize local d=9.25 u.CellPadding=UDim2.new(0,a.X*(d/882),0,a.X*(d/882))u.CellSize=UDim2.new(0,a.X*.22902494331066,0,a.X*.13151927437642)end local k=Instance.new("\083\099\114\101\101\110\071\117\105")k.Name="\083\116\111\114\101\086\105\101\119"k.DisplayOrder=2 k.Parent=script.Parent x=Instance.new("\073\109\097\103\101\076\097\098\101\108")x.BackgroundTransparency=1 x.Position=UDim2.new(.5,0,1.5,0)x.AnchorPoint=Vector2.new(.5,.5)x.Image="\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\056\057\049\051\053\049"x.Parent=k G.new(k,1.4,function()x.Size=UDim2.new(1.26,0,.9,0)x.SizeConstraint=Enum.SizeConstraint.RelativeYY end,function()x.Size=UDim2.new(.9,0,.64285714285714,0)x.SizeConstraint=Enum.SizeConstraint.RelativeXX end)local Y=Instance.new("\073\109\097\103\101\076\097\098\101\108")Y.BackgroundTransparency=1 Y.AnchorPoint=Vector2.new(1,0)Y.Size=UDim2.new(.065,0,.065,0)Y.SizeConstraint=Enum.SizeConstraint.RelativeYY Y.Position=UDim2.new(1,0,0,0)Y.ZIndex=4 Y.Parent=x local r=p.new(Y,UDim2.new(1,0,1,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\051\048\050\052\056\056","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\051\048\050\052\051\056","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\049\051\048\050\052\054\053")local i=Instance.new("\083\099\114\111\108\108\105\110\103\070\114\097\109\101")i.BackgroundTransparency=1 i.BorderSizePixel=0 i.Size=UDim2.new(.97785160575858,0,.6171875,0)i.Position=UDim2.new(.011074197120709,0,.3453125,0)i.TopImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\055\048\054\056\051\055\050\048\053"i.MidImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\055\048\054\056\051\054\057\054\048"i.BottomImage="\114\098\120\097\115\115\101\116\105\100\058\047\047\053\055\048\054\056\051\054\055\052\054"i.Parent=x u=Instance.new("\085\073\071\114\105\100\076\097\121\111\117\116")u.HorizontalAlignment=Enum.HorizontalAlignment.Center u.Parent=i;(x:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\083\105\122\101")):Connect(f)f();(u:GetPropertyChangedSignal("\065\098\115\111\108\117\116\101\067\111\110\116\101\110\116\083\105\122\101")):Connect(function()i.CanvasSize=UDim2.new(0,0,0,u.AbsoluteContentSize.Y)end)i.CanvasSize=UDim2.new(0,0,0,u.AbsoluteContentSize.Y)local S=Instance.new("\073\109\097\103\101\076\097\098\101\108")S.BackgroundTransparency=1 S.Size=UDim2.new(.17,0,.1,0)S.Position=UDim2.new(.69,0,.1,0)S.Parent=x local z=p.new(S,UDim2.new(1,0,1,0),"\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\050\053\055\055\050","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\050\053\055\053\049","\114\098\120\097\115\115\101\116\105\100\058\047\047\049\051\050\054\050\053\055\054\051")z.Button.MouseButton1Down:Connect(function()if H then H=false V="\067\097\110\100\121"K()wait()H=true end end)local q=Instance.new("\084\101\120\116\076\097\098\101\108")q.BackgroundTransparency=1 q.Size=UDim2.new(.09,0,.06,0)q.Position=UDim2.new(.7,0,.18,0)q.Font=Enum.Font.Antique q.TextScaled=true q.Text=tostring(g:GetValue("\067\117\114\114\101\110\099\121"))q.TextColor3=Color3.new(.93333333333333,.80392156862745,1.0)q.TextStrokeColor3=Color3.new(0,0,0)q.TextStrokeTransparency=0 q.TextXAlignment=Enum.TextXAlignment.Right q.Parent=x;(g:GetValueChangedSignal("\067\117\114\114\101\110\099\121")):Connect(function()q.Text=tostring(g:GetValue("\067\117\114\114\101\110\099\121"))end)local I=Instance.new("\070\114\097\109\101")I.BackgroundTransparency=1 I.Position=UDim2.new(.02,0,.25,0)I.Size=UDim2.new(.96,0,.06,0)I.Parent=x for a,d in pairs(a)do local T=Instance.new("\073\109\097\103\101\076\097\098\101\108")T.BackgroundTransparency=1 T.Size=UDim2.new(3.6153846153846,0,1,0)T.SizeConstraint=Enum.SizeConstraint.RelativeYY T.Parent=I local j=X.new(T,d)j.Button.MouseButton1Down:Connect(function()if H then H=false V=d K()wait()H=true end end)end local Z=Instance.new("\085\073\076\105\115\116\076\097\121\111\117\116")Z.Padding=UDim.new(.025,0)Z.HorizontalAlignment=Enum.HorizontalAlignment.Center Z.FillDirection=Enum.FillDirection.Horizontal Z.Parent=I for a,d in pairs(D)do table.insert(R,m.new(a,i))end K()local F=(script.Parent:WaitForChild("\071\117\105\079\112\101\110\083\116\097\116\101\115")):WaitForChild("\083\116\111\114\101")B:Register(k,F)F.Changed:Connect(function()x:TweenPosition(UDim2.new(.5,0,F.Value and.5 or 1.5,0),"\079\117\116","\081\117\097\100",.5,true)end)r.Button.MouseButton1Down:Connect(function()x:TweenPosition(UDim2.new(.5,0,1.5,0),"\079\117\116","\081\117\097\100",.5,true)F.Value=false end)
--[[
TheNexusAvenger

Allows players to buy items.
--]]

local STORE_CATEGORIES = {
    "Featured",
    "Companions",
    "Customize",
    "Unlockables",
}



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

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

local StoreItems = ReplicatedStorageProject:GetResource("GameData.Item.Store")
local ImageEventBinder = ReplicatedStorageProject:GetResource("UI.Button.ImageEventBinder")
local WideTextButtonDecorator = ReplicatedStorageProject:GetResource("UI.Button.WideTextButtonDecorator")
local AspectRatioSwitcher = ReplicatedStorageProject:GetResource("UI.AspectRatioSwitcher")
local DisplayOrderController = ReplicatedStorageProject:GetResource("State.DisplayOrderController")
local PlayerData = ReplicatedStorageProject:GetResource("State.PlayerData").GetPlayerData(Players.LocalPlayer)
local StoreItem = require(script:WaitForChild("StoreItem"))

local DB = true
local CurrentCategory = "Featured"
local StoreFrames = {}
local Background,StoreGridLayout



--[[
Updates the visible store frames.
--]]
local function UpdateVisibleStoreFrames()
    for _,Button in pairs(StoreFrames) do
        Button:UpdateVisibility(CurrentCategory)
    end
end

--[[
Updates the store grid constraint.
--]]
local function UpdateStoreGridLayout()
    local BackgroundSize = Background.AbsoluteSize
    local Padding = (882 - (4 * 202))/8
    StoreGridLayout.CellPadding = UDim2.new(0,BackgroundSize.X * (Padding/882),0,BackgroundSize.X * (Padding/882))
    StoreGridLayout.CellSize = UDim2.new(0,BackgroundSize.X * (202/882),0,BackgroundSize.X * (116/882))
end



--Create the ScreenGui.
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "StoreView"
ScreenGui.DisplayOrder = 2
ScreenGui.Parent = script.Parent

--Create the container.
Background = Instance.new("ImageLabel")
Background.BackgroundTransparency = 1
Background.Position = UDim2.new(0.5,0,1.5,0)
Background.AnchorPoint = Vector2.new(0.5,0.5)
Background.Image = "rbxassetid://132891351"
Background.Parent = ScreenGui

AspectRatioSwitcher.new(ScreenGui,1.4,function()
    Background.Size = UDim2.new(0.9 * 1.4,0,0.9,0)
    Background.SizeConstraint = Enum.SizeConstraint.RelativeYY
end,function()
    Background.Size = UDim2.new(0.9,0,0.9/1.4,0)
    Background.SizeConstraint = Enum.SizeConstraint.RelativeXX
end)

local CloseImage = Instance.new("ImageLabel")
CloseImage.BackgroundTransparency = 1
CloseImage.AnchorPoint = Vector2.new(1,0)
CloseImage.Size = UDim2.new(0.065,0,0.065,0)
CloseImage.SizeConstraint = Enum.SizeConstraint.RelativeYY
CloseImage.Position = UDim2.new(1,0,0,0)
CloseImage.ZIndex = 4
CloseImage.Parent = Background
local CloseButton = ImageEventBinder.new(CloseImage,UDim2.new(1,0,1,0),"rbxassetid://131302488","rbxassetid://131302438","rbxassetid://131302465")

local StoreScrollingFrame = Instance.new("ScrollingFrame")
StoreScrollingFrame.BackgroundTransparency = 1
StoreScrollingFrame.BorderSizePixel = 0
StoreScrollingFrame.Size = UDim2.new(1 - (20/903),0,1 - (245/640),0)
StoreScrollingFrame.Position = UDim2.new(10/903,0,221/640,0)
StoreScrollingFrame.TopImage = "rbxassetid://5706837205"
StoreScrollingFrame.MidImage = "rbxassetid://5706836960"
StoreScrollingFrame.BottomImage = "rbxassetid://5706836746"
StoreScrollingFrame.Parent = Background

StoreGridLayout = Instance.new("UIGridLayout")
StoreGridLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
StoreGridLayout.Parent = StoreScrollingFrame
Background:GetPropertyChangedSignal("AbsoluteSize"):Connect(UpdateStoreGridLayout)
UpdateStoreGridLayout()
StoreGridLayout:GetPropertyChangedSignal("AbsoluteContentSize"):Connect(function()
    StoreScrollingFrame.CanvasSize = UDim2.new(0,0,0,StoreGridLayout.AbsoluteContentSize.Y)
end)
StoreScrollingFrame.CanvasSize = UDim2.new(0,0,0,StoreGridLayout.AbsoluteContentSize.Y)

--Create the category buttons.
local CandyCategoryImage = Instance.new("ImageLabel")
CandyCategoryImage.BackgroundTransparency = 1
CandyCategoryImage.Size = UDim2.new(0.17,0,0.1,0)
CandyCategoryImage.Position = UDim2.new(0.69,0,0.1,0)
CandyCategoryImage.Parent = Background
local CandyCategoryButton = ImageEventBinder.new(CandyCategoryImage,UDim2.new(1,0,1,0),"rbxassetid://132625772","rbxassetid://132625751","rbxassetid://132625763")

CandyCategoryButton.Button.MouseButton1Down:Connect(function()
    if DB then
        DB = false
        CurrentCategory = "Candy"
        UpdateVisibleStoreFrames()
        wait()
        DB = true
    end
end)

local CandyText = Instance.new("TextLabel")
CandyText.BackgroundTransparency = 1
CandyText.Size = UDim2.new(0.09,0,0.06,0)
CandyText.Position = UDim2.new(0.7,0,0.18,0)
CandyText.Font = Enum.Font.Antique
CandyText.TextScaled = true
CandyText.Text = tostring(PlayerData:GetValue("Currency"))
CandyText.TextColor3 = Color3.new(238/255,205/255,255/255)
CandyText.TextStrokeColor3 = Color3.new(0,0,0)
CandyText.TextStrokeTransparency = 0
CandyText.TextXAlignment = Enum.TextXAlignment.Right
CandyText.Parent = Background

PlayerData:GetValueChangedSignal("Currency"):Connect(function()
    CandyText.Text = tostring(PlayerData:GetValue("Currency"))
end)

local CategoriesFrame = Instance.new("Frame")
CategoriesFrame.BackgroundTransparency = 1
CategoriesFrame.Position = UDim2.new(0.02,0,0.25,0)
CategoriesFrame.Size = UDim2.new(0.96,0,0.06,0)
CategoriesFrame.Parent = Background

for _,Category in pairs(STORE_CATEGORIES) do
    local CategoryImage = Instance.new("ImageLabel")
    CategoryImage.BackgroundTransparency = 1
    CategoryImage.Size = UDim2.new(188/52,0,1,0)
    CategoryImage.SizeConstraint = Enum.SizeConstraint.RelativeYY
    CategoryImage.Parent = CategoriesFrame
    local CategoryButton = WideTextButtonDecorator.new(CategoryImage,Category)

    CategoryButton.Button.MouseButton1Down:Connect(function()
        if DB then
            DB = false
            CurrentCategory = Category
            UpdateVisibleStoreFrames()
            wait()
            DB = true
        end
    end)
end

local ListLayout = Instance.new("UIListLayout")
ListLayout.Padding = UDim.new(0.025,0)
ListLayout.HorizontalAlignment = Enum.HorizontalAlignment.Center
ListLayout.FillDirection = Enum.FillDirection.Horizontal
ListLayout.Parent = CategoriesFrame

--Create the store items.
for TransactionId,_ in pairs(StoreItems) do
    table.insert(StoreFrames,StoreItem.new(TransactionId,StoreScrollingFrame))
end
UpdateVisibleStoreFrames()

--Connect opening and closing.
local OpenValue = script.Parent:WaitForChild("GuiOpenStates"):WaitForChild("Store")
DisplayOrderController:Register(ScreenGui,OpenValue)
OpenValue.Changed:Connect(function()
    Background:TweenPosition(UDim2.new(0.5,0,OpenValue.Value and 0.5 or 1.5,0),"Out","Quad",0.5,true)
end)
CloseButton.Button.MouseButton1Down:Connect(function()
    Background:TweenPosition(UDim2.new(0.5,0,1.5,0),"Out","Quad",0.5,true)
    OpenValue.Value = false
end)