I have created a custom inventory this works very well, but now I wanted to make a system in which the item, for example, on slot 5 is moved to slot 4 if slot 4 is empty.
I've made a script that partially works, however, duplicates the script the item to be moved
Here is the script:
Local Script:
wait () while true do wait (1) local ID2Replace = 0 local Slots = 0 local ActiveSlot = game.Players.LocalPlayer.PlayerSystem.ActiveSlot.Value local SaveSlot = game.Players.LocalPlayer.PlayerSystem:FindFirstChild("SaveSlot"..ActiveSlot) if SaveSlot ~= nil then local SlotsLength = SaveSlot.Inventory.Bag1:GetChildren() repeat Slots = Slots + 1 local CurrentSlot = SaveSlot.Inventory.Bag1:FindFirstChild("SLOT"..Slots) if CurrentSlot.Value ~= "0, 0" then local Slot2Test = SaveSlot.Inventory.Bag1:FindFirstChild("SLOT"..Slots - 1) if Slot2Test ~= nil then if Slot2Test.Value == "0, 0" and Slot2Test ~= nil then Slot2Replace = Slots local DataTable = { ["OldSlot"] = CurrentSlot.Name, ["NewSlot"] = Slot2Test.Name, ["OldSlotValue"] = CurrentSlot.Value } game.Workspace.System.Events.ReplaceEvent:FireServer(DataTable) end end end until Slot2Replace ~= 0 or Slots == #SlotsLength end end
ServerScript:
script.Parent.Parent.Events.ReplaceEvent.OnServerEvent:Connect(function (Player, DataTable) local ActiveSlot = Player.PlayerSystem.ActiveSlot.Value local SaveSlot = Player.PlayerSystem:FindFirstChild("SaveSlot"..ActiveSlot) if SaveSlot ~= nil then local OldSlot = SaveSlot.Inventory.Bag1:FindFirstChild(DataTable["OldSlot"]) local NewSlot = SaveSlot.Inventory.Bag1:FindFirstChild(DataTable["NewSlot"]) if OldSlot ~= nil and NewSlot ~= nil then OldSlot.Value = "0, 0" NewSlot.Value = DataTable["OldSlotValue"] end end end)
That solved the problem:
OldSlot.Value = "0, 1" wait (1) OldSlot.Value = "0, 0"
Just from what I can see, you deleted the old slot before copying it over, so all you need to change is:
NewSlot.Value = DataTable["OldSlotValue"] OldSlot.Value = "0, 0"
I'm not sure if this works because I can't test it