Attempt to index nil with Instance

So I was trying to make a combat system and it involved a dictionary. Well when I finished the dictionary script there was an error (the error is the title of this topic) and it just stopped the entire combat system. I would really appreciate it if someone could help / try to help me, I’ve been trying to solve this for a few hours.

The script:

local Dictionary = require(script.Dictionary)

local DictionaryHandler = {}

function DictionaryHandler.find(player, action)

return Dictionary[action][player]

end

function DictionaryHandler.add(player, action)

if not Dictionary[action][player] then

Dictionary[action][player] = true

end
end

function DictionaryHandler.remove(player, action)

if Dictionary[action][player] then

Dictionary[action][player] = nil
end
end
return DictionaryHandler

I tried my best to indent it, lol

1 Like

hey mate do you have a copy of the output error :+1:

2 Likes

ServerScriptService.DictionaryHandler:6: attempt to index nil with Instance - Server - DictionaryHandler:6

Here you go :wink:

That means Dictionary[action] doesn’t exist

Do you know how I could fix it or something? Because the script was from a tutorial and the person recording didn’t really explain it.

What does the Dictionary ModuleScript look like, or do you have a link to the tutorial

I’ll just show you the Dictionary module script.

local Dictionary = {
[“Stunned”] = {},
}

return Dictionary

It’s a short script

When you’re calling methods in the DictionaryHandler ModuleScript, are you using Stunned for action or something else? If you’re using something else, you’ll have to add it to the table like Stunned:

local Dictionary = {
   ["Stunned"] = {},
   ["WhatElseYou'reUsing"] = {},
}

return Dictionary
1 Like

I’m just using stunned for the combat system

Is it spelt and capitalized the same in your script

1 Like

Yeah it is spelled correctly in both scripts

Are you calling the function properly?

dictionary.add(player, "Stunned")
And not doing:
dictionary:add(player, "Stunned")

1 Like

Ay bro, tsym I added “Stunned” in the parantheses and everything works. Thank you so much bro

1 Like

No problem! Glad to help :smile:

char limit