Sorting slot issue

Can someone please help me why does this behavior happen? it should be sorting it and assigning the slot to its current index

local inv = {}

local tab = {
	Name = "TestWeapon",
	Type = "Gear",
	Class = "Weapon",
	Slot = 0,
	Stackable = false,
	BaseStats = {
		Power = 20,
		AttackSpeed = 6,
	}
}

local function sortSlot(curInv)
	for i,v in pairs(curInv) do
		v.Slot = i
	end
	return curInv
end

table.insert(inv, tab)
table.insert(inv, tab)
table.insert(inv, tab)
table.insert(inv, tab)
table.insert(inv, tab)
table.insert(inv, tab)

sortSlot(inv)

print(inv)

I dont know if i’m tripping or not because this behavior is messing with my inventory system
and this issue just appeared out of nowhere without apparent cause

newInv = sortSlot(inv);

It still doesnt work still the same result. my inventory system was working fine yesterday, but then this bug appeared and it’s messing with it and I cant find exactly what’s causing this behaviour

maybe remove the return function cause shouldnt the function be a void then

Same result, I really dont think i’m doing wrong in my code, it’s in roblox problem i guess, try to replicate it copy my code in a server script and run it

local function sortSlot(curInv)
     for i=1,#curInv do
         curInv[i].Slot = i;
     end
end

Fixed, it was a reference issue, i should have inserted a deepCopy for each insertion to differentiate

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.