Attempt To Index Local "r" (A Nil Value)

I’m trying to make a case opening system but I get this error that the r is a nil value

13%20AM

28%20AM

I tried different methods but it just keeps on giving an error on that line. Any help would be appreciated!

your GetRarity only returns something if b["Name"] == Name i assume it didn’t find a match thus r is nil as GetRarity returns nothing

It’s getting the information from the module script inside ReplicatedStorage

04%20AM

care to debug in the GetRarity function after the if b["Name"] == Name then or put a print after it and run the code. if no print (or debug) appears it means it didn’t pass the if statement

It printed

care to debug above the if statement. i assume that due to the for loop the GetRarity is in it must have atleast have one that doesn’t return anything

Also printed

i assume then that you mis spelled something in a script as coding is quite capital sensitive. this is easily fixed (if that’s the case) by adjusting the:

if b["Name"] = Name then

to

if string.lower(b["Name"]) = string.lower(Name) then

I just tried your code but it didn’t seem to work. Anything I try, it just keeps sending the error to that line. I have no idea what the problem is.

i got one last thing in mind that might help trying to find the issue. care to print above the local r the c["raritytype"] variable: print(c["RarityType"])

I just figured out the problem by printing that. I had a misspelled rarity in the Items module so it only printed out 3 instead of all 4. That fixed it thanks!