#GetAmountOf()

1 messages · Page 1 of 1 (latest)

lilac maple
#

its counting it but when i set the value it says 1 instead of the x11

slender kelp
#

bro u aint serious right

#

ur counting instances not names

lilac maple
#

well now its saying 0

#

instead of 1

#

i tried that already

#

@slender kelp

#

i even added my else statemends inside the for loop

slender kelp
#

its saying 0 bc u didnt give the function the itemname

lilac maple
#

if statements*

slender kelp
crisp peakBOT
#

studio** You are now Level 38! **studio

slender kelp
#

that should be yo first line

#

bc i cant press enter on discord mobile 😭

lilac maple
#

ok ill give it a shot

crisp peakBOT
#

studio** You are now Level 8! **studio

lilac maple
#

does that line go into the local function or in the loop

#

?

#

@slender kelp

slender kelp
#

thats the entire line

#

it replaces ur local function getamountof(itemName)

#

in the for loop, you do; if v.Name == itemName

lilac maple
#

local function GetAmountOf(itemname)
itemname = itemname.Name
local amount = 0
for i, v in pairs(plrinv["Inventory"])do
if v == itemname then
amount += 1
end
end
return amount
end

for i, v in plrinv["Inventory"] do 
    
    local AmountInInv = GetAmountOf(v)
    print(AmountInInv)
    

    if AmountInInv < hotbarslots then 
        print("Adding to hotbar")

    end

    if AmountInInv > hotbarslots then 
        print("Adding to inventory")
    end

end
end
#

ok so heres what i changed it to and its still printing zero

rain rain
#

is there a codeblock command in here

#

nope

lilac maple
#

no idea

#

@slender kelp

slender kelp
#

ok

#

local function GetAmountOf(itemname)
itemname = itemname.Name
local amount = 0
for i, v in pairs(plrinv["Inventory"])do
if v.Name == itemname then
amount += 1
end
end
return amount
end

for i, v in plrinv["Inventory"] do 
    
    local AmountInInv = GetAmountOf(v)
    print(AmountInInv)
    

    if AmountInInv < hotbarslots then 
        print("Adding to hotbar")

    end

    if AmountInInv > hotbarslots then 
        print("Adding to inventory")
    end

end
end
#

fixed

#

👍

lilac maple
#

idk what you did but it worked

#

youre a genius

#

thanks so much!

slender kelp
#

i literally added .Name in the for loop