Err: Attempt to index nil with 'WaitForChild'

I have two files as seen below, the TrelloAPI and my own script called groupBanScript;

I’ve ran into the error below with my first line and have not found anything to fix it.

Line 1
local TrelloAPI = require(groupBanScript:WaitForChild("TrelloAPI"))

attempt to index nil with 'WaitForChild' (line 1 which is above)

If this script is inside the groupBanScript then just reference it as script like

local TrelloAPI = require(script:WaitForChild("TrelloAPI"))

Perfect, if I needed to make more scripts with this API though, do I need to recreate the API in another file or is there an easier way?

No, but you need to correctly reference the API module path.

For example if this is how it structured

- ServerScriptService
    - groupBanScript
        - TrelloAPI
    - anotherScriptThatRequireTrelloAPI

then in anotherScriptThatRequireTrelloAPI you will call it

local TrelloAPI = require(script.Parent.groupBanScript:WaitForChild("TrelloAPI"))
-- script is reference to the anotherScriptThatRequireTrelloAPI itself
-- Parent will reference the ServerScriptService
-- and from that you follow the script tree

Hope this clear enough

1 Like