Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local ItemInfo = require(script.Parent.Items)
- local DataStore = game:GetService("DataStoreService"):GetDataStore("ItemsAndStats")
- game.Players.PlayerAdded:connect(function(player)
- if player:WaitForDataReady() then
- game.StarterGui.ResetPlayerGuiOnSpawn = false
- print("Creating " .. player.Name .. "'s inventory.")
- local PlayerDir = game.Players:FindFirstChild(player.Name)
- local Gui = PlayerDir.PlayerGui.ScreenGui
- local MaxSlots = 28
- local CurrentSlot = 0
- local Row = 0
- local Line = 0
- local Increment = 50
- Gui.LoadingScreen.Visible = true
- local Inventory = Instance.new("IntValue",player)
- Inventory.Name = "Inventory"
- while MaxSlots > CurrentSlot do
- local GuiIncrement = UDim2.new(0,50*Row,0,50*Line)
- local BarIncrement = 14 * CurrentSlot
- if CurrentSlot < MaxSlots then
- CurrentSlot = CurrentSlot + 1
- Row = Row + 1
- local Slot = Instance.new("Frame",Gui.Inventory)
- Slot.Name = "Slot" .. CurrentSlot
- Slot.Size = UDim2.new(0,50,0,50)
- Slot.Position = GuiIncrement
- Slot.BorderSizePixel = 0
- local Item = Instance.new("IntValue",Inventory)
- Item.Name = "Item" .. CurrentSlot
- local ItemSlot = Instance.new("IntValue",Gui.Inventory["Slot"..CurrentSlot])
- ItemSlot.Name = "Slot"
- ItemSlot.Value = CurrentSlot
- local ItemIdent = Instance.new("IntValue",player.Inventory["Item" .. CurrentSlot])
- ItemIdent.Name = "Id"
- Gui.LoadingScreen.LoadingBarInner.Size = UDim2.new (0,10+BarIncrement,0,20)
- Gui.LoadingScreen.LoadingLabel.Text = "Loading: Item_" .. CurrentSlot
- if DataStore:GetAsync(player.Name .. "Item_"..CurrentSlot) then
- if DataStore:GetAsync(player.Name .. "Item_"..CurrentSlot) >= 0 then
- Item.Value = DataStore:GetAsync(player.Name .. "Item_"..CurrentSlot)
- local ItemValue = Instance.new("IntValue",Gui.Inventory["Slot"..CurrentSlot])
- ItemValue.Name = "Item"
- ItemValue.Value = DataStore:GetAsync(player.Name .. "Item_"..CurrentSlot)
- end
- else
- local ItemValue = Instance.new("IntValue",Gui.Inventory["Slot"..CurrentSlot])
- ItemValue.Name = "Item"
- ItemValue.Value = 0
- end
- if DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot) then
- if DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot) > 0 then
- ItemIdent.Value = DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot)
- local Ident = Instance.new("IntValue",Gui.Inventory["Slot"..CurrentSlot])
- Ident.Name = "Id"
- Ident.Value = DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot)
- print("Loaded " .. ItemInfo[Ident.Value].Name .. " With a quantity of " .. DataStore:GetAsync(player.Name .. "Item_" .. CurrentSlot) .. " With an Id Value of " .. DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot) .. "." )
- else
- ItemIdent.Value = 0
- print("Slot " .. CurrentSlot)
- end
- if DataStore:GetAsync(player.Name .. "Item_" .. CurrentSlot) > 0 then
- if DataStore:GetAsync(player.Name .. "Item_" .. CurrentSlot) > 1 then
- local StackNumber = Instance.new("TextLabel",Gui.Inventory["Slot" .. CurrentSlot])
- StackNumber.Name = "StackNumberLabel"
- StackNumber.Position = UDim2.new(0,13,0,10)
- StackNumber.FontSize = "Size8"
- StackNumber.Text = DataStore:GetAsync(player.Name .. "Item_" .. CurrentSlot)
- if Inventory["Item"..CurrentSlot].Value >= 1000 and Inventory["Item"..CurrentSlot].Value <= 999999 then
- player.PlayerGui.ScreenGui.Inventory["Slot"..CurrentSlot].StackNumberLabel.Text = string.sub(Inventory["Item"..CurrentSlot].Value,1,1) .. "k"
- if Inventory["Item"..CurrentSlot].Value >= 10000 then
- player.PlayerGui.ScreenGui.Inventory["Slot"..CurrentSlot].StackNumberLabel.Text = string.sub(Inventory["Item"..CurrentSlot].Value,1,2) .. "k"
- end
- if Inventory["Item"..CurrentSlot].Value >= 100000 then
- player.PlayerGui.ScreenGui.Inventory["Slot"..CurrentSlot].StackNumberLabel.Text = string.sub(Inventory["Item"..CurrentSlot].Value,1,3) .. "k"
- end
- elseif Inventory["Item"..CurrentSlot].Value >= 1000000 and Inventory["Item"..CurrentSlot].Value < 1000000000 then
- player.PlayerGui.ScreenGui.Inventory["Slot"..CurrentSlot].StackNumberLabel.Text = string.sub(Inventory["Item"..CurrentSlot].Value,1,1) .. "m"
- player.PlayerGui.ScreenGui.Inventory["Slot"..CurrentSlot].StackNumberLabel.TextColor3 = Color3.new(0, 255, 0)
- else
- player.PlayerGui.ScreenGui.Inventory["Slot"..CurrentSlot].StackNumberLabel.Text = Inventory["Item"..CurrentSlot].Value
- end
- end
- if DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot) > 0 then
- local Img = Instance.new("ImageButton",Gui.Inventory["Slot"..CurrentSlot])
- Img.Size = UDim2.new(0,50,0,50)
- Img.Image = ItemInfo[DataStore:GetAsync(player.Name .. "ItemId_" .. CurrentSlot)].UsedImage
- Img.Name = "ItemButton"
- Img.BorderSizePixel = 0
- end
- end
- end
- if Row == 4 then
- Row = 0
- Line = Line + 1
- end
- if CurrentSlot == MaxSlots then
- print(player.Name .. "'s inventory has been created.")
- end
- end
- wait(0.01)
- end
- Gui.LoadingScreen.Visible = false
- Gui.ResetInventory.Visible = true
- end
- end)
- while true do
- for i,v in pairs (game.Players:GetPlayers()) do
- print("Saving")
- v.PlayerGui.ScreenGui.Saving.Visible = true
- v.PlayerGui.ScreenGui.Saving.Text = "Saving! This may take a while!"
- local MaxItems = 28
- local CurrentItem = 0
- while CurrentItem < MaxItems do
- CurrentItem = CurrentItem + 1
- DataStore:SetAsync(v.Name .. "Item_" .. CurrentItem, v.Inventory["Item"..CurrentItem].Value)
- if v.Inventory["Item"..CurrentItem].Value >= 1 then
- DataStore:SetAsync(v.Name .. "ItemId_" .. CurrentItem, v.Inventory["Item"..CurrentItem].Id.Value)
- print("Saved " .. ItemInfo[v.Inventory["Item"..CurrentItem].Id.Value].Name .. " With a quantity of " .. v.Inventory["Item"..CurrentItem].Value .. " and an ID Value of " .. v.Inventory["Item"..CurrentItem].Id.Value .. ".")
- else
- print("No item in Slot " .. CurrentItem)
- end
- if CurrentItem == MaxItems then
- v.PlayerGui.ScreenGui.Saving.Text = "Saved"
- wait(2)
- v.PlayerGui.ScreenGui.Saving.Visible = false
- end
- end
- end
- wait(120)
- end
Advertisement
Advertisement