This is gonna kinda tricky to explain, but I’ll try. So I’ve found a problem with my inventory where when I update it, any movements I make from the client get reverted (you can drag your items around the inventory to different slots, but I never connected those changes to the server)
So here, I move 2 items into a stored slot, then use one of my axes until it breaks. When it breaks I fire an update to the client, which is the players inventory, and so when they client gets their inventory from server, there items are still in their original spots.
Hope this gif gives the general idea
So, as you can see, my two axes which I moved, go put back into their original slots, so I need to do some client-server stuff to change them in the server.
What I’ve got
-- Client
local OriginalFrame = v.Parent
v.Parent = frame.Parent
frame.Parent = OriginalFrame
local SlotSection1
local SlotSection2
if OriginalFrame.Name == 'MainSlots' then
SlotSection1 = {
Section = 'Main',
Number = OriginalFrame.Parent.Name
}
else
SlotSection1 = {
Section = 'Stored',
Number = OriginalFrame.Parent.Name
}
end
if frame.Name == 'MainSlots' then
SlotSection2 = {
Section = 'Main',
Number = frame.Parent.Name
}
else
SlotSection2 = {
Section = 'Stored',
Number = frame.Parent.Name
}
end
ItemMoved:FireServer(SlotSection1, SlotSection2)
So this basically occurs when the item has been moved. So my logic was OriginalFrame is the item you are moving, then ‘frame’ is where you are moving it toooo. So it should look like this. if I move item in Slot 1 (main) to Slot 3 (stored)
SlotSection1 = {Section = 'Stored', Number = '3'}
SlotSection2 = {Section = 'Main', Number = '1'}
Then server would go
local function MovedItem(player, slotSelection1, slotSelection2)
local User = PlayerData[player.UserId]
if not User then return end
local OriginalData = User.Inventory[slotSelection1.Section][slotSelection1.Number]
User.Inventory[slotSelection1.Section][slotSelection1.Number] = User.Inventory[slotSelection2.Section][slotSelection2.Number]
User.Inventory[slotSelection2.Section][slotSelection2.Number] = OriginalData
end
And so like the item in their slot 1 main inventory would be moved over to the Slot 3 stored inventory and vice versa
-- Inventory layout
Inventory = {
Main = {
[1] = {Type = 'Tool', Name = 'Wooden Axe', Durability = 30},
[2] = {Type = 'Tool', Name = 'Wooden Axe', Durability = 30},
[3] = {Type = 'Tool', Name = 'Wooden Axe', Durability = 5},
[4] = {Type = 'Tool', Name = 'Wooden Axe', Durability = 10},
[5] = {Type = 'Tool', Name = 'Wooden Axe', Durability = 20}
},
Stored = {
[1] = {},
[2] = {},
[3] = {},
[4] = {},
[5] = {},
[6] = {},
[7] = {},
[8] = {},
[9] = {},
[10] = {}
}
}
TL;DR basically, when I move my inventory around, I want to communicate with the server and corrospond the moved items to the server, so the server can update my inventory