#Problem with tables returning nil

1 messages · Page 1 of 1 (latest)

vague needle
#

SetState is applying the state correctly on the player. Returns the table of states of the player in the module.SetState function.

although, module.ReturnStates returns nil

This is how the state is being set on the character right now:

-- SERVER SCRIPT, PARENT IS A PROXIMITY PROMPT INSIDE OF A PART
script.Parent.Triggered:Connect(function()
    
    stateManager.SetState(game.Workspace.Rig, "Parrying", true, 10) -- plr, stateKey, true or false, duration
    
end)

This is how I'm getting the states

-- MODULE SCRIPT
function module.ReturnStates(plr)
    print("Returning State")
    print(plr)
    return states[plr]
end

print(plr) = returns Rig (game.Workspace.Rig)

SetState prints out the table of all the states set on the player aswell, and it prints them all out correctly

Using the state table for an if statement:

-- THIS IS IN A LOCAL SCRIPT 
local states = stateManager.ReturnStates(v.Parent)
print(states)
                    
if table.find(states, "Parrying") then

v.Parent = Rig

#

Errors:
Workspace.liamvf.InputManager.M1:62: attempt to index nil with 'Parrying' - Client - M1:62 (This is an error coming from the 3rd listed script)

#

M1:62 is the if statement

#

This doesnt do anything different aswell:

if states["Parrying"] then
eternal lark
#

states is nil

vague needle
modest flickerBOT
#

studio** You are now Level 4! **studio

eternal lark
vague needle
eternal lark
#

Yes

vague needle
# eternal lark Yes
function module.ReturnStates(plr)
    print("Returning State")
    print(plr)
    return states[plr]
end

this

eternal lark
vague needle
#

it dies

#

itll return nothing

vague needle
eternal lark
vague needle
#

tried to do this but it changed nothing 😭

eternal lark
#

If you do nil[key] it's going to error

#

You need to check if the states aren't nil before indexing it

#

You indexed it inside the if statement instead of checking

vague needle
humble harness
#

My question is why are you using a pixel font..

#

just makes it so much more weirder...

vague needle
humble harness
#

@vague needle Can you trying printing states for me like:

function module.ReturnStates(plr)
    print("Returning State")
    print(states)
    return states[plr]
end
#

and then let us know what prints

vague needle
humble harness
#

thats why its returning nil

#

where is the part that sets states

vague needle
#

but it says there's a state applied on the Rig player

vague needle
humble harness
#

btw are you able to send it in code blocks in future js cus it makes it easier to read lol

#

is line 34

print(states[plr])
vague needle
#

oops yeah sorry

vague needle
pallid jolt
vague needle
humble harness
#

since your returning a value it should work pretty similarly to the module script

pallid jolt
#

Or you could have each player have their own “action” in a form of a value on their player and check to see changes on the server side

#

But remote functions are easier to use

vague needle
vague needle
humble harness
#

so what youd do is
client:
local states = RemoteFunction:FireServer()

Sever:

function RemoteFunction.OnServerInvoke()
— put the script that gets the states from the module script here

   return states

end

#

wait

#

i believe that’s how you use remote functions but i’d suggest looking at the specific documentation

#

as i’m on mobile right now

vague needle
#

alright thats all good

#

thanks though