I’m adding a report system to my announcement system. Just to be on the safe side, messages are logged and when the player reports a message the server verifies that the message was actually sent. Here’s the problem: it’s not working.
Here’s part a sample of the code that adds the index to the table (remember that this is only a sample of the whole thing)
local timeStamp = os.time() --Time player sent the message, will be useful if message is reported for data regarding the time the message was sent
table.insert(log,1,{["Message"] = broadcastFiltering,["UserId"] = player.UserId, ["Time"] = timeStamp})
log[40] = nil -- To prevent too much memory usage, this will limit the table to 40 indexes
Now here’s the search function that isn’t working ( the log
variable has already been defined)
function searchLog(msg,userId,timeSent)
local index = table.find(log,{["Message"] = msg,["UserId"] = userId,["Time"] = timeSent})
if index ~= nil then
return true
else return false end
end
Lastly here’s the code that searches the log
report.OnServerEvent:Connect(function(player,msg,reason,timeSent,userId,additionalComment)
local findMessage = searchLog(msg,userId,timeSent)
repeat wait() until findMessage ~= nil
if findMessage == true then
print("Message Found")
end
end)
It doesn’t print "Message found"
.
I did a test earlier to see if the indexes match up and they were the same here’s the output: (not current version of code)
> Have a great day! 485407994 1643853850 - Data sent
> Have a great day! 485407994 1643853850 - Log Data
I did the test using this code:
print(msg,userId,timeSent.." - Data sent")
print(log[1].Message,log[1].UserId,log[1].Time.." - Log Data")
Please ignore the fact that the player could be reporting not the most recent announcement this is just a test.
Why is it not working?