Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game.Players.LocalPlayer
- --Inventory Handling
- local currentPlayerInventory = nil;
- local currentSection = "Weapons"
- local inventoryOpened = true
- local InventoryUI = script.Parent:WaitForChild("Inventory")
- local InventoryEvent = game.ReplicatedStorage:WaitForChild("Remotes").Inventory
- local Module3D = require(game.ReplicatedStorage:WaitForChild("Modules").Module3D)
- function model(tool)
- local newModel = Instance.new("Model")
- newModel.Name = tool.Name
- for x, a in pairs(tool:GetChildren()) do
- if a:IsA("BasePart") then
- a:Clone().Parent = newModel
- end
- end
- return newModel
- end
- function place3DHandler(slot,item)
- if item.Type == "Weapon" then
- if game.ReplicatedStorage.Tools:FindFirstChild(item.Name) then
- local newTool = model(game.ReplicatedStorage.Tools:FindFirstChild(item.Name))
- local new3DHandler = Module3D:Attach3D(slot,newTool)
- new3DHandler:SetActive(true)
- if game.ReplicatedStorage.Tools:FindFirstChild(item.Name):FindFirstChild("Rotation") then
- local newRotation = game.ReplicatedStorage.Tools:FindFirstChild(item.Name):FindFirstChild("Rotation")
- new3DHandler:SetCFrame(new3DHandler:GetCFrame() * CFrame.Angles(math.rad(newRotation.Value.X),math.rad(newRotation.Value.Y),math.rad(newRotation.Value.Z)))
- end
- return new3DHandler
- end
- end
- end
- local destroy = {}
- function refreshInventory(Section)
- if inventoryOpened == true and currentPlayerInventory ~= nil then
- if currentPlayerInventory[Section] ~= nil then
- for x, Slot in pairs(InventoryUI.Scene.Container:GetChildren()) do
- if Slot:IsA("UIGridLayout") == false then
- Slot:Destroy();
- end
- end
- for x,y in pairs(destroy) do
- y:End()
- end
- if currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)] ~= nil and currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)] ~= "None" then
- local newSlot = InventoryUI:WaitForChild("Slot"):Clone()
- newSlot.ItemName.Text = currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)].Name
- newSlot.Parent = InventoryUI.Scene.Container
- newSlot.Visible = true
- local new3DHandler = place3DHandler(newSlot.ImageLabel,currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)])
- table.insert(destroy,new3DHandler)
- newSlot.Equip.MouseButton1Click:Connect(function()
- InventoryEvent:FireServer("Unequip",currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)])
- end)
- end
- for x, invSlot in pairs(currentPlayerInventory[Section]) do
- local newSlot = InventoryUI:WaitForChild("Slot"):Clone()
- newSlot.ItemName.Text = invSlot.Name
- newSlot.Parent = InventoryUI.Scene.Container
- newSlot.Visible = true
- local new3DHandler = place3DHandler(newSlot.ImageLabel,currentPlayerInventory["Equipped"..string.sub(Section,1,#Section-1)])
- table.insert(destroy,new3DHandler)
- newSlot.Equip.MouseButton1Click:Connect(function()
- InventoryEvent:FireServer("Equip",invSlot)
- end)
- end
- end
- end
- end
- InventoryEvent.OnClientEvent:connect(function(Action,...)
- local Args = {...}
- if Action == "Update" then
- currentPlayerInventory = Args[1]
- if inventoryOpened == true then
- refreshInventory(currentSection)
- end
- end
- end)
- -- // SHOP BUTTON // --
- --[[script.Parent.Icons.Inventory.MouseButton1Down:Connect(function()
- if inventoryOpened == true then
- InventoryUI:TweenPosition(UDim2.new(-.5,0,.2,0),"Out","Quint",.15,true)
- refreshInventory(currentSection)
- inventoryOpened = false
- else
- InventoryUI:TweenPosition(UDim2.new(.25,0,.2,0),"Out","Quint",.15,true)
- inventoryOpened = true
- end
- end)]]
- for x, Button in pairs(InventoryUI.Menu:GetChildren()) do
- if Button:IsA("ImageButton") or Button:IsA("TextButton") then
- Button.MouseButton1Click:connect(function()
- if inventoryOpened == true then
- currentSection = Button.Name
- refreshInventory(Button.Name)
- end
- end)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement