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
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.
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
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.
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
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