Here I am trying to add the item name to the table. I am trying to make it short so I don't want to check if the table is empty and do an if statement which will make it twice as long. Is there another way to do this without checking if the table is empty? This also seems to do the same if theres only one item in the table.
**1.**No the event isn't the problem just in case.
**2.**I tried to do for i,v in ipairs(table) but it did the same thing or even broke the whole script.
**2.**The Item argument is a string value.
module.EquippedItems = {}
module.EquipItem = function(Item)
local WasEquipped = false
for i = 1,#module.EquippedItems do
if module.EquippedItems[i] == Item then
WasEquipped = true
end
end
if WasEquipped == true then
for i = 1,#module.EquippedItems do
if module.EquippedItems[i] == Item then
table.remove(module.EquippedItems,i)
EquipItemEvent:FireServer(Item,false)
if Holder_Inventory:FindFirstChild(Item) then
local SetItem = Holder_Inventory:WaitForChild(Item)
SetItem.BackgroundColor3 = Color3.fromRGB(163, 162, 165)
end
end
end
elseif not WasEquipped then
for i = 1,#module.EquippedItems,1 do
if module.EquippedItems[i] == nil then
table.insert(module.EquippedItems,i,Item)
EquipItemEvent:FireServer(Item,true)
if Holder_Inventory:FindFirstChild(Item) then
local SetItem = Holder_Inventory:WaitForChild(Item)
SetItem.BackgroundColor3 = Color3.fromRGB(0,255,0)
end
end
end
end
end

3 comments
https://developer.roblox.com/en-us/ Everything you need starts with this link. And sure, learning from previous scripts like the one you posted is great, but if you don't know the basics, it will be a problem for you in the long run.
I understand everything I was just checking if anyone has an alternative to the working one which checks if the table is empty and occupies the first spot in the array.
https://developer.roblox.com/en-us/articles/Table The information is right there, you just need to put in some effort in finding this stuff before asking a question.