Attempt to index nil with instance

When I tested my game, and pressed the bind to activate combat, all that happened was: ServerScriptService.Stuff.StunningHandler:14: attempt to index nil with Instance
local Stunning = require(script:WaitForChild(“Stunning”))

local StunningHandler = {}

function StunningHandler.addTo(Player,Action)
Stunning[Action][Player] = true
end

function StunningHandler.removeFrom(Player,Action)
Stunning[Action][Player] = nil
end

function StunningHandler.findPlayer(Player,Action)
return Stunning[Action][Player]
end

return StunningHandler

local sus = {}
local b = sus == {} -- it's a boolean

print(sus.amogus) --> nil
print(b.amogus) --> attempt index boolean with amogus
3 Likes

Greetings RoboL1nk,

It seems to be an error to do with you trying to access an “item” in a module script which doesn’t exist. If you are trying to access an item in a table, I suggest debugging it first with a simple print.

local Stunning = require(script:WaitForChild(“Stunning”))

local StunningHandler = {}

function StunningHandler.addTo(Player,Action)
    print(Stunning[Action])
    print(Stunning[Action][Player])
    Stunning[Action][Player] = true
end

function StunningHandler.removeFrom(Player,Action)
    print(Stunning[Action])
    print(Stunning[Action][Player])
    Stunning[Action][Player] = nil
end

function StunningHandler.findPlayer(Player,Action)
    print(Stunning[Action])
    print(Stunning[Action][Player])
    return Stunning[Action][Player]
end

return StunningHandler

If the first print fails that means “Stunning” doesn’t exist. From there you can take more actions to fix this.

1 Like

Was able to Combine this print and another one mamytema sent and I was able to figure out the mistake. Thank you so much.