I’m attempting to have it where a function reads all of the tables values and check for a players UserId and if it finds it in the said area, it will print that it completed through it’s function.
Issues
My issue is that i’m apparently… attempt to index function with "ID"
Solutions
I’ve tried having it do a check with no table in the ID area but that failed and gave me the same error.
Script
local ChatTagModule = {
["AlexTatums Tag"] = {
ID = {571909198},
Description = "Description.",
Function = function(plr)
print("Completed")
end,
}
,
["ETag"] = {
ID = {2314546},
Description = "Description.",
Function = function(plr)
print("Completed")
end,
}
}
function ChatTagModule.CheckPlayer(plr)
for _,ModuleFunction in pairs (ChatTagModule) do
print(plr.UserId)
if table.find(ModuleFunction.ID,plr.UserId) then -- This is the line that gives the error.
ModuleFunction.Function(plr)
return true
else
return false
end
end
end
return ChatTagModule
I think the issue is that it’s somehow getting a function somewhere, it could either be the Function in those tables or the CheckPlayer Function. Try removing the Function parts of the table entries and see if the error persists
This I’m not sure if this is related but shouldn’t the . be a :? Correct me if I’m wrong
The reason you’re getting that error is because you’re assigning a function within the ChatTagModule table called CheckPlayer, so when you loop through the contents of ChatTagModule you’re iterating over a function which doesn’t contain any data that you are trying to index, which in this case would be ID. To solve this, you should create a separate table within the ChatTagModule table which contains the tag data to iterate over.
local ChatTagModule = {
TagData = {
["AlexTatums Tag"] = {
ID = {571909198},
Description = "Description.",
Function = function(plr)
print("Completed")
end,
}
,
["ETag"] = {
ID = {2314546},
Description = "Description.",
Function = function(plr)
print("Completed")
end,
}
}
}
function ChatTagModule.CheckPlayer(plr)
for _,ModuleFunction in pairs (ChatTagModule.TagData) do
print(plr.UserId)
if table.find(ModuleFunction.ID,plr.UserId) then -- This is the line that gives the error.
ModuleFunction.Function(plr)
return true
else
return false
end
end
end
return ChatTagModule