Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Here is what a client menu framework would look like,
- lots of assets being preloaded, to ensure the stability of the game (client side)
- Also demonstrating some different usages of remote client events/functions.
- ]]
- local sl = require(game.ReplicatedStorage.ModuleScripts.CrossNetwork.ShopLogic)
- local cgm = require(game.ReplicatedStorage.ModuleScripts.CrossNetwork.CandyGlobalModules)
- local gd = require(game.ReplicatedStorage.ModuleScripts.CrossNetwork.GameData)
- local gm = require(game.ReplicatedStorage.ModuleScripts.CrossNetwork.GenericGlobalModules)
- local bm = require(game.ReplicatedStorage.ModuleScripts.CrossNetwork.BuyableModule)
- local MarketplaceService = game:GetService("MarketplaceService")
- local m = {}
- m.Init = function(plr)
- local plrGui = plr:WaitForChild('PlayerGui')
- local plrLollis = plrGui:WaitForChild('Lollis')
- local plrBackpacks = plrGui:WaitForChild('Backpacks')
- local plrInventory = plrGui:WaitForChild('Inventory')
- local plrMainFrame = plrGui:WaitForChild('MainFrame')
- local plrValueFrame = plrGui:WaitForChild('ValueFrame')
- local plrBuyMore = plrGui:WaitForChild('BuyMore')
- local plrInv = plrGui:WaitForChild('Inventory')
- local plrGs = plrGui:WaitForChild('GamepassShop')
- local settingsBtn = plrMainFrame.Frame:WaitForChild('Settings')
- local twitterBtn = plrMainFrame.Frame:WaitForChild('Twitter')
- local tradingBtn = plrMainFrame.Frame:WaitForChild('Trading')
- local sellBtn = plrMainFrame.Frame:WaitForChild('Sell')
- local backpackBtn = plrMainFrame.Frame:WaitForChild('Backpack')
- local gamepassBtn = plrMainFrame.Frame:WaitForChild('Gamepasses')
- local settingsFrame = plrMainFrame:WaitForChild('SettingsFrame')
- local twitterFrame = plrMainFrame:WaitForChild('TwitterFrame')
- local tradingFrame = plrMainFrame:WaitForChild('TradingFrame')
- local rebirths = plrValueFrame.Frame:WaitForChild('Rebirths')
- local cash = plrValueFrame.Frame:WaitForChild('Cash')
- local candy = plrValueFrame.Frame:WaitForChild('Candy')
- settingsBtn.MouseButton1Click:Connect(function()
- settingsFrame.Visible = not settingsFrame.Visible
- twitterFrame.Visible = false
- tradingFrame.Visible = false
- end)
- twitterBtn.MouseButton1Click:Connect(function()
- twitterFrame.Visible = not twitterFrame.Visible
- settingsFrame.Visible = false
- tradingFrame.Visible = false
- end)
- sellBtn.MouseButton1Click:Connect(function()
- game.ReplicatedStorage.RemoteEvents.GotoSell:FireServer()
- end)
- tradingBtn.MouseButton1Click:Connect(function()
- tradingFrame.Visible = not tradingFrame.Visible
- twitterFrame.Visible = false
- settingsFrame.Visible = false
- end)
- backpackBtn.MouseButton1Click:Connect(function()
- plrInventory.Enabled = not plrInventory.Enabled
- end)
- gamepassBtn.MouseButton1Click:Connect(function()
- plrGs.Enabled = not plrGs.Enabled
- end)
- settingsFrame.CloseBtn.MouseButton1Click:Connect(function()
- settingsFrame.Visible = not settingsFrame.Visible
- end)
- tradingFrame.CloseBtn.MouseButton1Click:Connect(function()
- tradingFrame.Visible = not tradingFrame.Visible
- end)
- twitterFrame.CloseBtn.MouseButton1Click:Connect(function()
- twitterFrame.Visible = not twitterFrame.Visible
- end)
- settingsFrame.DisableCandyAnims.MouseButton1Click:Connect(function()
- if settingsFrame.DisableCandyAnims.Frame.ImageTransparency == 1 then
- settingsFrame.DisableCandyAnims.Frame.ImageTransparency = 0
- settingsFrame.EnableCandyAnims.Frame.ImageTransparency = 1
- end
- end)
- settingsFrame.EnableCandyAnims.MouseButton1Click:Connect(function()
- if settingsFrame.EnableCandyAnims.Frame.ImageTransparency == 1 then
- settingsFrame.EnableCandyAnims.Frame.ImageTransparency = 0
- settingsFrame.DisableCandyAnims.Frame.ImageTransparency = 1
- end
- end)
- settingsFrame.DisableCandyNotifications.MouseButton1Click:Connect(function()
- if settingsFrame.DisableCandyNotifications.Frame.ImageTransparency == 1 then
- settingsFrame.DisableCandyNotifications.Frame.ImageTransparency = 0
- settingsFrame.EnableCandyNotifications.Frame.ImageTransparency = 1
- end
- end)
- settingsFrame.EnableCandyNotifications.MouseButton1Click:Connect(function()
- if settingsFrame.EnableCandyNotifications.Frame.ImageTransparency == 1 then
- settingsFrame.EnableCandyNotifications.Frame.ImageTransparency = 0
- settingsFrame.DisableCandyNotifications.Frame.ImageTransparency = 1
- end
- end)
- settingsFrame.DisableTrading.MouseButton1Click:Connect(function()
- if settingsFrame.DisableTrading.Frame.ImageTransparency == 1 then
- local rv = game.ReplicatedStorage.RemoteFunctions.Trading:InvokeServer()
- repeat wait() until rv == true
- settingsFrame.DisableTrading.Frame.ImageTransparency = 0
- settingsFrame.EnableTrading.Frame.ImageTransparency = 1
- end
- end)
- settingsFrame.EnableTrading.MouseButton1Click:Connect(function()
- if settingsFrame.EnableTrading.Frame.ImageTransparency == 1 then
- local rv = game.ReplicatedStorage.RemoteFunctions.Trading:InvokeServer()
- repeat wait() until rv == true
- settingsFrame.EnableTrading.Frame.ImageTransparency = 0
- settingsFrame.DisableTrading.Frame.ImageTransparency = 1
- end
- end)
- game.Players[plr.Name].leaderstats.Coins.Changed:Connect(function()
- cash.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats.Coins.Value)
- end)
- game.Players[plr.Name].leaderstats.Rebirths.Changed:Connect(function()
- rebirths.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats.Rebirths.Value)
- end)
- game.Players[plr.Name].leaderstats.Candy.Changed:Connect(function()
- candy.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats.Candy.Value)
- end)
- game.Players[plr.Name].leaderstats['Rebirth Gems'].Changed:Connect(function()
- candy.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats['Rebirth Gems'].Value)
- end)
- spawn(function()
- wait(1)
- candy.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats['Rebirth Gems'].Value)
- cash.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats.Coins.Value)
- rebirths.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats.Rebirths.Value)
- candy.TextLabel.Text = gm.ConvertNumToText(game.Players[plr.Name].leaderstats.Candy.Value)
- end)
- plrLollis.ImageLabel.CloseBtn.MouseButton1Click:Connect(function()
- if plr:FindFirstChild('whichShop') then
- local v = plr.whichShop.Value
- plr.whichShop:Destroy()
- game.ReplicatedStorage.RemoteEvents.MoveBack:FireServer('lolli')
- sl.ClientExitStores(plr)
- end
- end)
- plrBackpacks.ImageLabel.CloseBtn.MouseButton1Click:Connect(function()
- if plr:FindFirstChild('whichShop') then
- local v = plr.whichShop.Value
- plr.whichShop:Destroy()
- game.ReplicatedStorage.RemoteEvents.MoveBack:FireServer('backpacks')
- sl.ClientExitStores(plr)
- end
- end)
- plrBackpacks.Left.MouseButton1Click:Connect(function()
- sl.MoveLeft(plr, 'backpacks')
- end)
- plrBackpacks.Right.MouseButton1Click:Connect(function()
- sl.MoveRight(plr, 'backpacks')
- end)
- plrBackpacks.ImageLabel.BuyBtn.MouseButton1Click:Connect(function()
- game.ReplicatedStorage.RemoteEvents.Buy:FireServer('backpacks', plrBackpacks.ImageLabel.BuyBtn.Parent.ItemName.Text)
- end)
- plrLollis.Left.MouseButton1Click:Connect(function()
- sl.MoveLeft(plr, 'lollipops')
- end)
- plrLollis.Right.MouseButton1Click:Connect(function()
- sl.MoveRight(plr, 'lollipops')
- end)
- plrLollis.ImageLabel.BuyBtn.MouseButton1Click:Connect(function()
- game.ReplicatedStorage.RemoteEvents.Buy:FireServer('lollipops', plrLollis.ImageLabel.BuyBtn.Parent.ItemName.Text)
- end)
- game.ReplicatedStorage.PlayerData[tostring(plr.UserId)].UnlockedBackpacks.ChildAdded:Connect(function()
- cgm.UpdateEquip(plr, 'backpacks')
- end)
- game.ReplicatedStorage.PlayerData[tostring(plr.UserId)].UnlockedBackpacks.ChildRemoved:Connect(function()
- cgm.UpdateEquip(plr, 'backpacks')
- end)
- game.ReplicatedStorage.PlayerData[tostring(plr.UserId)].UnlockedLollis.ChildAdded:Connect(function()
- cgm.UpdateEquip(plr, 'lollipops')
- end)
- game.ReplicatedStorage.PlayerData[tostring(plr.UserId)].UnlockedLollis.ChildRemoved:Connect(function()
- cgm.UpdateEquip(plr, 'lollipops')
- end)
- delayTime = false
- plrBackpacks.ImageLabel.Equip.MouseButton1Click:Connect(function()
- if not delayTime then
- delayTime = true
- local retValue = game.ReplicatedStorage.RemoteFunctions.Equip:InvokeServer(plrBackpacks.ImageLabel.ItemName.Text, 'equip', 'backpacks')
- repeat wait() until retValue == true
- delayTime = false
- end
- end)
- plrBackpacks.ImageLabel.UnEquip.MouseButton1Click:Connect(function()
- if not delayTime then
- delayTime = true
- local retValue = game.ReplicatedStorage.RemoteFunctions.Equip:InvokeServer(plrBackpacks.ImageLabel.ItemName.Text, 'unequip', 'backpacks')
- repeat wait() until retValue == true
- delayTime = false
- end
- end)
- plrLollis.ImageLabel.Equip.MouseButton1Click:Connect(function()
- if not delayTime then
- delayTime = true
- local retValue = game.ReplicatedStorage.RemoteFunctions.Equip:InvokeServer(plrLollis.ImageLabel.ItemName.Text, 'equip', 'lollipops')
- repeat wait() until retValue == true
- delayTime = false
- end
- end)
- plrLollis.ImageLabel.UnEquip.MouseButton1Click:Connect(function()
- if not delayTime then
- delayTime = true
- local retValue = game.ReplicatedStorage.RemoteFunctions.Equip:InvokeServer(plrLollis.ImageLabel.ItemName.Text, 'unequip', 'lollipops')
- repeat wait() until retValue == true
- delayTime = false
- end
- end)
- -- inventory
- local camPoint = workspace.Shops.View.CamPart
- local camSubjct = workspace.Shops.View.CamSubject
- local selected
- local category
- local categoryTypes = {'pets', 'hats', 'backpacks', 'lollipops'}
- local subConn
- lastRot = 0.025
- conns = {}
- plrInv.ImageLabel.Close.MouseButton1Click:Connect(function()
- plrInv.Enabled = false
- subConn = nil
- plrInv.ImageLabel.Item:ClearAllChildren()
- end)
- local function hideFrames()
- for k,v in pairs(plrInv.ImageLabel:GetChildren()) do
- if v:IsA('ScrollingFrame') and v.Name ~= 'SelectFrame' then
- for x,y in pairs(v:GetChildren()) do
- for i=1, #conns do conns[i]:Disconnect() end
- conns = {} -- after disconnecting the connections ensure new table
- if y:IsA('TextButton') then y:Destroy() end
- end
- v.Visible = false
- end
- end
- for k,v in pairs(plrInv.ImageLabel:GetChildren()) do
- if v:IsA('TextLabel') then
- v.Visible = false
- end
- end
- end
- local tBtn = plrInv.ImageLabel.Lollipops.TextButton:Clone()
- plrInv.ImageLabel.Lollipops.TextButton:Destroy()
- local plrData = game.ReplicatedStorage.PlayerData[tostring(plr.UserId)]
- local ulp = plrData.UnlockedPets
- local eqp = plrData.EquipedPets
- local ull = plrData.UnlockedLollis
- local eql = plrData.EquipedLolli
- local ulb = plrData.UnlockedBackpacks
- local eqb = plrData.EquipedBackpack
- local ulh = plrData.UnlockedHats
- local eqh = plrData.EquipedHats
- local toUpdateDirs = {ulp, eqp, ull, eql, ulb, eqb, ulh, eqh}
- local toUpdateDirsPar = {'Pets', 'Pets', 'Lollipops', 'Lollipops', 'Backpacks', 'Backpacks', 'Hats', 'Hats'}
- plrInv.ImageLabel.Equip.MouseButton1Click:Connect(function()
- db = false
- if not db then
- db = true
- if selected then
- local retValue = game.ReplicatedStorage.RemoteFunctions.Equip:InvokeServer(selected.Text, 'equip', category)
- repeat wait() until retValue == true or retValue == -1
- end
- db = false
- end
- end)
- plrInv.ImageLabel.UnEquip.MouseButton1Click:Connect(function()
- db = false
- if not db then
- db = true
- if selected then
- local retValue = game.ReplicatedStorage.RemoteFunctions.Equip:InvokeServer(selected.Text, 'unequip', category)
- repeat wait() until retValue == true or retValue == -1
- end
- db = false
- end
- end)
- local viewPort = Instance.new('Camera')
- plrInv.ImageLabel.Item.CurrentCamera = viewPort
- viewPort.Parent = plrInv.ImageLabel.Item
- ictn = 1
- game:GetService('RunService').RenderStepped:Connect(function()
- if ictn > 360 then ictn = 1 end
- lastRot = ictn + 0.025
- ictn = ictn + 1
- end)
- viewPort.CFrame = CFrame.new(camPoint.Position+Vector3.new(0, 0, 6), camSubjct.Position)
- local function findData(area)
- for k,v in pairs(gd[area]) do
- if v[1] == selected.Text then
- return v
- end
- end
- end
- local function findItem(dir, itemName)
- for k,v in pairs(dir:GetDescendants()) do
- if v.Name == itemName then return v:Clone() end
- end
- end
- local function attatchHandle(btn, area)
- local conn = btn.MouseButton1Click:Connect(function()
- if subConn then subConn:Disconnect() end
- subConn = nil
- local otherAreas = {plrInv.ImageLabel.Backpacks, plrInv.ImageLabel.Hats, plrInv.ImageLabel.Lollipops, plrInv.ImageLabel.Pets}
- for x, y in pairs(otherAreas) do
- for k,v in pairs(y:GetDescendants()) do
- if v:IsA('TextButton') then
- if tostring(v.TextColor) == tostring(BrickColor.new('Really black')) then
- v.TextColor = BrickColor.new(Color3.fromRGB(255, 255, 255))
- end
- end
- end
- end
- if selected == btn and tostring(btn.TextColor)==tostring(BrickColor.new('Really black')) then
- btn.TextColor = BrickColor.new(Color3.fromRGB(255, 255, 255))
- end
- selected = btn
- -- make updates on data
- local data = findData(area)
- if area == 'Lollipops' then
- plrInv.ImageLabel.LollipopsData.ItemName.Text = data[1]
- plrInv.ImageLabel.LollipopsData.Multiplier.Text = 'x' .. gm.ConvertNumToText(data[3])
- elseif area == 'Backpacks' then
- plrInv.ImageLabel.BackpacksData.ItemName.Text = data[1]
- plrInv.ImageLabel.BackpacksData.Storage.Text = gm.ConvertNumToText(data[3]) .. ' spaces'
- elseif area == 'Hats' then
- plrInv.ImageLabel.HatsData.ItemName.Text = data[1]
- plrInv.ImageLabel.HatsData.Multiplier.Text = 'x' .. gm.ConvertNumToText(data[2])
- plrInv.ImageLabel.HatsData.SpeedMultiplier.Text = 'x' .. data[3]
- elseif area == 'Pets' then
- plrInv.ImageLabel.PetsData.ItemName.Text = data[1]
- plrInv.ImageLabel.PetsData.Multiplier.Text = 'x' .. gm.ConvertNumToText(data[2])
- plrInv.ImageLabel.PetsData.SpeedMultiplier.Text = 'x' .. data[3]
- end
- -- setup viewport
- plrInv.ImageLabel.Item:ClearAllChildren()
- local p = findItem(game.ReplicatedStorage.GameObjects[area], btn.Text)
- p:SetPrimaryPartCFrame(camSubjct.CFrame)
- spawn(function()
- local myconn = game:GetService('RunService').RenderStepped:Connect(function()
- pcall(function()
- local cf = CFrame.new()
- cf = CFrame.new(p:GetPrimaryPartCFrame().p) * CFrame.Angles(0, math.rad(lastRot), 0)
- p:SetPrimaryPartCFrame(cf)
- end)
- end)
- repeat wait() until p.PrimaryPart == nil
- myconn:Disconnect()
- end)
- wait(.01)
- p.Parent = plrInv.ImageLabel.Item
- end)
- conns[#conns+1] = conn
- end
- local gAmt
- local function getAmount(dir, objName)
- gAmt = 0
- for k,v in pairs(dir:GetDescendants()) do
- if v.Name == objName then
- gAmt = gAmt + 1
- end
- end
- return gAmt
- end
- local function getColoredAmount(toUpdate, objName)
- local dir = plrInv.ImageLabel[toUpdate]
- gAmt = 0
- for k,v in pairs(dir:GetDescendants()) do
- if v:IsA('TextButton') then
- if v.Text == objName then
- gAmt = gAmt + 1
- end
- end
- end
- return gAmt
- end
- local function updateEquiped(btn, toUpdate)
- local eDirs = {eqp, eql, eqb, eqh}
- for k,v in pairs(eDirs) do
- for x,y in pairs(v:GetDescendants()) do
- if btn.Text == y.Name then
- local amt = getAmount(v, y.Name)
- local camt = getColoredAmount(toUpdate, y.Name)
- if camt <= amt then
- btn.TextColor = BrickColor.new(Color3.fromRGB(0, 255, 45))
- end
- return -- ensure not more than one is done
- end
- end
- end
- end
- local framesToUpdate = {'Pets', 'Lollipops', 'Backpacks', 'Hats'}
- local function updateInv(toUpdate)
- for k,v in pairs(toUpdateDirs) do
- if toUpdateDirsPar[k] == toUpdate then
- for x,y in pairs(v:GetChildren()) do
- local btn = tBtn:Clone()
- btn.Text = y.Name
- attatchHandle(btn, toUpdate)
- btn.Parent = plrInv.ImageLabel[toUpdate]
- updateEquiped(btn, toUpdate)
- end
- end
- end
- for k,v in pairs(framesToUpdate) do
- local f = plrInv.ImageLabel[v]
- local scaleY = #f:GetChildren() * 0.05
- f.CanvasSize = UDim2.new(0, 0, scaleY, 0)
- end
- end
- local dirsToWatch = {
- {'Pets', {ulp, eqp}},
- {'Lollipops', {ull, eql}},
- {'Backpacks', {ulb, eqp}},
- {'Hats', {ulh, eqh}},
- }
- for k,v in pairs(dirsToWatch) do
- for x,y in pairs(v[2]) do
- y.ChildAdded:Connect(function()
- hideFrames()
- plrInv.ImageLabel[v[1]].Visible = true
- plrInv.ImageLabel[v[1] .. 'Data'].Visible = true
- updateInv(v[1])
- end)
- y.ChildRemoved:Connect(function()
- hideFrames()
- plrInv.ImageLabel[v[1]].Visible = true
- plrInv.ImageLabel[v[1] .. 'Data'].Visible = true
- updateInv(v[1])
- end)
- end
- end
- for k,v in pairs(plrInv.ImageLabel.SelectFrame:GetChildren()) do
- if v:IsA('TextButton') then
- v.MouseButton1Click:Connect(function()
- category = string.lower(v.Text)
- hideFrames()
- plrInv.ImageLabel[v.Text].Visible = true
- plrInv.ImageLabel[v.Text .. 'Data'].Visible = true
- updateInv(v.Text)
- end)
- end
- end
- -- gamepass shop
- local pass = plrGs.ImageLabel.ScrollingFrame.ImageLabel:Clone()
- plrGs.ImageLabel.ScrollingFrame.ImageLabel:Destroy()
- local passTable = bm.GetPasses()
- plrGs.ImageLabel.ScrollingFrame.CanvasSize = UDim2.new(0, 0, #passTable*.2+0.43, 0)
- for k,v in pairs(passTable) do
- local i = MarketplaceService:GetProductInfo(v[1], Enum.InfoType.GamePass)
- local n = i.Name
- local d = i.Description
- local r = i.PriceInRobux
- local cp = pass:Clone()
- cp.Desc.Text = d
- cp.Title.Text = n
- cp.Cost.TextButton.Text = 'R $' .. tostring(r)
- cp.Img.Image = 'rbxassetid://' .. tostring(i.IconImageAssetId)
- spawn(function()
- cp.Cost.TextButton.MouseButton1Click:Connect(function()
- local hasPass = false
- local success, message = pcall(function()
- hasPass = MarketplaceService:UserOwnsGamePassAsync(plr.UserId, v[1])
- end)
- if not success then
- warn("Error while checking if player has pass: " .. tostring(message))
- return
- end
- if not hasPass then
- MarketplaceService:PromptGamePassPurchase(plr, v[1])
- end
- end)
- end)
- cp.Parent = plrGs.ImageLabel.ScrollingFrame
- end
- plrGs.ImageLabel.Close.MouseButton1Click:Connect(function()
- plrGs.Enabled = false
- end)
- local parts = plrValueFrame.Frame:GetChildren()
- for k,v in pairs(parts) do
- local obj = v.Name
- v.More.MouseButton1Click:Connect(function()
- -- in game buying
- end)
- end
- end
- return m
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement