ServerScriptService.DictonaryHandler:6: attempt to index nil with 'Stunned'

Pretty simple but I just cannot tie my head around the current issue that the Dictionary is going through.

Here’s the script.

Dic = require(script.Dictonary)

local DictonaryHandler = {}

function DictonaryHandler.find(Player, Action)
	return Dic[Player][Action]
end

function DictonaryHandler.add(Player, Action)
	if not  Dic[Player][Action] then
		Dic[Player][Action] = true
	end
end

function DictonaryHandler.remove(Player, Action)
	if Dic[Player][Action] then
		 Dic[Player][Action] = nil
	end
end

return DictonaryHandler
1 Like

In your DictionaryHandler function, print out Player and Action to make sure they aren’t nil.

1 Like

Well, it’ll print out the players name, and that they’re stunned.
image

My best guess as to what is going on is maybe the script doesn’t know that Dic[Player] is a dictionary. I’ve had a similar issue before and configuring the table usually helps:

function DictonaryHandler.add(Player, Action)
    if not Dic[Player] then
		Dic[Player] = {}
	elseif not Dic[Player][Action] then
		Dic[Player][Action] = true
	end
end

I tried something and somehow it worked out. I just switched the values to be [Action][Player] instead of the other way around.

Dic[Player] is nil when the code runs, which means the Player isn’t added to the dictionary yet or has left the game.