#Functions on ModuleScript unable to get tables, returns nil

1 messages · Page 1 of 1 (latest)

fair bloom
#

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
opaque flame
#

uh it's likely something to do with the whole value vs reference thing on roblox studio, if the value you're trying to get is not in a table and is a primitive value (boolean, number etc.) then what you get is a copy of the actual value and not the reference of the value

#

basically

#

try putting your value in a table

fair bloom
fair bloom
#

anyone able to help?

outer cloak