Why is the table nil?

Hey, so I have this script in ServerScriptService:

	local isredactst = false
	if table.find(require(game.ServerScriptService.Modules["RedactModule"]).redact,Player.Name) then
		local isredactst = true
	end```

And I have this ModuleScript: 
```lua
local redact = {
    "Megami_Shin",
    "TheRewd"
}

return(redact)```

But I get this error: ServerScriptService.Player.PlayerAdded:63: invalid argument #1 to 'find' (table expected, got nil)

I have tried making the script this: 
```lua
    local isredactst = false
    if table.find(require(game.ServerScriptService.Modules["RedactModule"]),Player.Name) then
        local isredactst = true
    end```

And while that does not error, it does not set the variable to true, any ideas why?

It’s likely it does not set it to true because the isredactst in the if statement is local to the if statement only, so outside of the scope it will reference the isredactst that is set to false, use this

local isredactst = false
if table.find(require(game.ServerScriptService.Modules["RedactModule"]),Player.Name) then
    isredactst = true
end

Or better yet just use the result of the statement immediately to get rid of the if statement

local isredactst = table.find(require(game.ServerScriptService.Modules["RedactModule"]),Player.Name) and true or false

Had to do the and true or false because table.find returns the index at which the thing has been found at or nil if it doesn’t exist in the table

2 Likes