Find Object in Dictionary by UserID

Hi! So I am using a Module Script Dictionary to list my Staff and their information for command purposes. But then the errors come in, attempt to index nil with 'Group'

I know what the error means but I need help with fixing it.

Thanks!


The Command Permission Check

local staffList = require(game:GetService("ReplicatedStorage"):WaitForChild("staffList"))

if (context.Name == "kick") then
   if (staffList[context.Executor.UserId].Group ~= context.Group) then
	return "NO PERMISSION"
   end
end

The Staff List (a module script)

local list = {
	{
		Username = "Boop_xy",
		UserID = 995959318,
		Group = "Owner"
	}
}

return list

It needs to be formatted like this and accessed as a dictionary, because right now it isn’t a dictionary.

local list = {
	995959318 = {
		Username = "Boop_xy",
		Group = "Owner"
	}
}

It’s saying, Assigned Expression must be a variable or a field


local list = {
	995959318 = {
		Username = "Boop_xy",
		Group = "Staff"
	}
}

return list

Maybe try checking if staffList[context.Executor.UserId] exists first before trying to read it’s Group value.

My bad, it’s been a while.

local list = {
	[995959318] = {
		Username = "Boop_xy",
		Group = "Staff"
	}
}
2 Likes

Perfecto, it works. Thanks you!

1 Like