#GetStates returns nil, even though the value I'm grabbing from a table actually exists

1 messages · Page 1 of 1 (latest)

clever arrow
#

These functions seem to be unable to grab states:
print(states[plr]) -> nil
Although, when I print states[plr] from the SetState function, it returns the wanted text... something that isn't nil / false
All of the listed functions are in the same ModuleScript located in ReplicatedStorage

function module.ReturnStates(plr)
    if states[plr] == nil then
        return nil
    else
        return states[plr]
    end
end


function module.GetStates(plr, stateKey)
    print(states[plr])
    if states[plr] then
        return states[plr][stateKey]
    end
end

Even though States are being set in a function right below them

function module.SetState(plr, stateKey, value, duration)
    if not states[plr] then
        print("Creating Branch at (states[plr])")
        states[plr] = {}
        print(states[plr])
    end
    
    states[plr][stateKey] = value
    print(states[plr])

    if duration and type(duration) == "number" then
        task.delay(duration, function()
            print("Deleted State")
            if states[plr] then
                states[plr][stateKey] = nil

                if next(states[plr]) == nil then
                    states[plr] = nil
                end
            end
        end)
    end

end
elder flame
clever arrow
#

the file "Script" is the code here

#

plr is a player

elder flame
clever arrow
#

i saw someone talk about value vs reference in my old post about this but i didn't understand

elder flame
#

is this what's returning nil?

clever arrow
elder flame
#

where is states defined?

clever arrow
#

it starts out completely empty

clever arrow
#

anyone know why this is happening???

somber sundialBOT
#

studio** You are now Level 6! **studio