Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ReplicatedStorage = game:GetService("ReplicatedStorage")
- local invUpdate = ReplicatedStorage:WaitForChild("invUpdate")
- local Inventory = {}
- local clientInv = {}
- local cService = game:GetService("CollectionService")
- local lastSlot = game.Players.LocalPlayer.PlayerGui:WaitForChild("Inventory").LastSlot
- slots = cService:GetTagged("invSlot")
- --Non Modules
- function invCheck(inv)
- if #clientInv == 0 then
- print("There is nothing in the client's Inventory.")
- clientInv = inv
- for i,v in pairs(clientInv) do
- if #slots == 0 then
- newSlot(i,v)
- else addSlots(i,v)
- end
- end
- end
- end
- --Modules
- function newSlot(name,value)
- local scrollingFrame = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame
- local firstText = Instance.new("TextButton")
- firstText.Name = name
- firstText.Parent = scrollingFrame
- firstText.Position = UDim2.new(.05, 0,.05, 0)
- firstText.Size = UDim2.new(.8, 0, .05, 0)
- firstText.BackgroundColor3 = Color3.new(255/255, 235/255, 168/255)
- firstText.ZIndex = 2
- firstText.Text = name.." - "..value
- cService:AddTag(firstText,"invSlot")
- scrollingFrame.Parent.LastSlot.Value = name
- local constraint = Instance.new("UISizeConstraint")
- constraint.Parent = firstText
- constraint.MaxSize = Vector2.new(250,50)
- print("new item"..name)
- end
- function addSlots(itemName,itemValue)
- local scrollingFrame = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame
- cService:GetTagged("invSlots")
- local nextText = Instance.new("TextButton")
- nextText.Name = itemName
- nextText.Position = lastSlot.Position+UDim2.new(0, 0, 0.055, 0)
- nextText.Size = lastSlot.Size
- nextText.BackgroundColor3 = lastSlot.BackgroundColor3
- nextText.ZIndex = 2
- nextText.Parent = scrollingFrame
- nextText.Text = itemName.." - "..itemValue
- cService:AddTag(nextText,"invSlot")
- local constraint = Instance.new("UISizeConstraint")
- constraint.Parent = nextText
- constraint.MaxSize = Vector2.new(250,50)
- scrollingFrame.Parent.LastSlot.Value = nextText.Name
- print("AddSlot Loaded")
- print(nextText.Name.. " and ".. scrollingFrame.Parent.LastSlot.Value)
- local scrollSizeY = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.CanvasSize.Y.Scale
- local scrollPosY = game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.Position.Y.Scale
- print(nextText.Position.Y.Scale)
- if nextText.Position.Y.Scale > scrollPosY+(scrollSizeY-nextText.Position.Y.Scale) then
- game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.CanvasSize=game.Players.LocalPlayer.PlayerGui.Inventory.invFrame.CanvasSize+UDim2.new(0,0,0,50)
- print("AddSlot End")
- else
- print("AddSlot End")
- end
- end
- function Inventory.UpdateSlots(remName)
- if #slots == 0 then
- print("There is nothing left in the inventory")
- else do
- for i,v in pairs(slots)do
- if v.Name == remName then
- print(v.Name.."="..remName)
- print(remName.Name.."being destroyed")
- wait(2)
- remName:Destroy()
- print("destroyed")
- end
- end
- end
- end
- end
- function Inventory.AddSlot(itemName,itemValue)
- print("Received Data from GetData")
- for i,v in ipairs(slots) do
- if v == itemName then
- v.Text = itemName.." - "..itemValue
- else do
- addSlots(itemName,itemValue)
- end
- end
- end
- end
- function onInvUpdate(player,inventory)
- if player == game.Players.LocalPlayer then
- print(player.Name.." = "..game.Players.LocalPlayer.Name)
- print("Updating Client Inventory")
- invCheck(inventory)
- end
- end
- invUpdate.OnClientEvent:Connect(onInvUpdate)
- return Inventory
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement