Table value returns nil when it should not be

73 Views Asked by At

My table:

local Cache = {
    SurvivalGameFramework = {
        parent = game.ServerStorage
    }
}

As you can probably tell, this table is not an empty value or "nil" but according to ROBLOX studio, Cache[1] is nil, and I've tried literally everything to figure out what is wrong with this engine.

print(Cache[1]) will return nil and so will Cache.SurvivalGameFramework[1].

1

There are 1 best solutions below

0
Luatic On

Cache[1] being nil is correct: The only key used in your Cache table is SurvivalGameFramework. Cache.SurvivalGameFramework in turn only has a parent key, so Cache.SurvivalGameFramework[1] is nil as well. Cache.SurvivalGameFramework.parent on the other hand would be game.ServerStorage.

A table t = {42} or t = {[1] = 42} would have t[1] == 42. A table t2 = {k = 42} or t2 = {["k"] = 42} has t2.k == 42 and t2["k"] == 42. Absent keys have nil values in Lua, so t2[1] is nil.