Adding a value to detect if no more slots are available in a for loop

Hello, I have a for loop and I was wondering if I could check to see if there are no available spaces in the for loop and if there are none then I want to call function. How can I do this?

for counter = 1,5 do
	local obj = UI:WaitForChild(counter)

	if obj.Val.Value == "" then
	    --add details
		break
	elseif obj.Val.Value == item.Name then
		--do more stuff
		break
	end
end

do you mean like if there are some stuff that is beyond the for loop range?

like the if statement checks if the item has a value, if it doesn’t then it adds one. The elseif statement adds onto that item’s value if it exists. If all of the slots are occupied I want to check this and then call a function.

i get what you mean by the if statement, but what do you mean by slots. Is it the 1 - 5 in the

?

the 1-5 are the amount of slots so there are 5 slots

im not sure if this is what you want.

Try creating a number variable, then add 1 if the (item ~= nil), after that check if the variable is less than 5, if its 5 then slots is full

so change the 5 to a variable then add 1 to another variable for each item that is added and then if it is equal then call a function?

just keep the

for counter = 1, 5 do

but add a number variable that adds 1 for each item, and call the function when its 5. Start the variable with 0.

How would i do this on the server? because i have a copy of this on the server but when I add a item it continues to add because the server is first.

what do you mean by this:

(character limit is annoying)

when i add a item im trying to check to see if it exists

if item then
	local itemType = ItemModule[item.Name]["Type"]
	local distanceFromItem = plr:DistanceFromCharacter(item.Position)
	if distanceFromItem < 10 and Inventory[itemType][item] == Inventory[itemType][item] then
		PickupItem:FireServer(item)
		wait(0.3)
	elseif distanceFromItem < 10 and Inventory[itemType][item] ~= Inventory[itemType][item] then
		if invfull == false then
			PickupItem:FireServer(item)
			wait(0.3)
		else
			FullInvWarn(item)
			return
		end
	end
end

this doesn’t work, can you help fix it?

you mean like the server will check if the item to pickup exists?

don’t worry about the server thing i can bypass that if i fix this because Im trying to test to see if the object is in the table, if it isn’t then add it and then if invfull which will be set to true when the 1,5 counter is equal to 5 etc. I want to see if it gives me an error but it doesn’t get past the elseif statement where the invfull == false takes place.

you said

because there is a

in there. What you are doing is checking if two literally the same object is not the same. Like the Instances or the object itself is the same. Tell me if I’m wrong but that is what I see on your script

yes, that is what i have, what do you suggest I can do instead?

on the if statement, what do you want to compare?
Correct me if this is wrong, but what I think you are TRYING to do is
1.check if player is within 10 studs away from the item
2a. then if that item is the same with an item you got, it will stack and you get like 2 of the same item which still takes one slot.
2b. But if the item is not the same with anything you have in your slots, it will go through another if statement
2b-i. this second if statement will check if your inventory is full. If it is full, it warns or something
2b-ii. but if not, then puts in your slots

yes, this is what im trying to achieve. Im still confused on how im supposed to do this?

on this part

is the Inventory[itemType][item] a gui, frame or what?

this is a table and it is saved to a main inventory type e.g. equipment, food.