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

1 messages · Page 1 of 1 (latest)

novel plaza
#

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
I tried making value a table aswell, in SetStates (states[plr][stateKey] = value = states[plr][stateKey] = {value}
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
bold blade
#

and which u reading in

novel plaza
#

huh

#

oh

bold blade
#

ik these are all in single module

#

but like

#

the one that calls the function

novel plaza
# bold blade the one that calls the function

this is what gets the data and returns it so it can go from the server into the client

local stateManagerRF = game.ReplicatedStorage.StateManager:FindFirstChild("StateManagerRF")

local stateManager = require(game.ReplicatedStorage.StateManager)

stateManagerRF.OnServerInvoke = function(plr)
    --print("ServerInvoke")
    --print(plr)
    local states = stateManager.ReturnStates(plr)
    --print(states)
    local stateKey = stateManager.GetStates(plr, "Parrying")
    --print(stateKey)
    if stateKey == nil then
        stateKey = false
    end

    return stateKey
end

and this is a script tied to a part with a ProximityPrompt in workspace

local stateManagerRF = game.ReplicatedStorage.StateManager.StateManagerRF

script.Parent.Triggered:Connect(function()
    
    stateManager.SetState(game.Workspace.Rig, "Parrying", true, 10)
    
end)
bold blade
#

on explorer

bold blade
novel plaza