Code erroring in one script but not the other

  1. What do you want to achieve?
    I want to use Configuration.
  2. What is the issue?
    I’m getting this error in the output.

attempt to index nil with ‘FindFirstChild’

  1. What solutions have you tried so far?
    I’ve look over forums including this and others for solutions.
local configuration = tool:FindFirstChildWhichIsA("Configuration", true)
enabled = configuration:FindFirstChild("EnabledValue").Value
equipped = configuration:FindFirstChild("EquippedValue").Value
throwable = configuration:FindFirstChild("Throwable").Value

Also, this is in a local script and this piece of code is working perfectly in a script but not a local one.

I don’t see an error in your post, could you describe it in more detail?

Is it something like attempt to index nil with "Value"?

If so, try replacing FindFirstChild with WaitForChild, since you’re assuming those configuration instances exist.

I just realized that, I’ll edit it into the post now.

1 Like

It looks like the first line with tool:FindFirstChildWhichIsA("Configuration", true) couldn’t find the configuration and returned nil which caused the later lines to stop functioning.

Perhaps it’s better to use WaitForChild or a chain of them to get to your configuration, although that would sort of ruin your whole reason for using a configuration in the first place.

Maybe you could use a function like this:

local function WaitForDescendantWhichIsA(instance, className)
    local desc = instance:FindFirstChildWhichIsA(className, true)
    if desc then return desc end

    local newDesc
        newDesc = instance.DescendantAdded:Wait()
    until newDesc:IsA(className)

    return newDesc

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.