Hey I am currently making an admin logging system yet it isn’t going as planned.
I am trying to print out the message if the message contains a sub-part of the command.
Ex: “/h”, “/kick”, etc.
The commands do not contain the slash (“/”) as it is given the slash in the admin script so it is a plain letter(s) or word.
It doesn’t give an error yet doesn’t print anything.
Here is my script:
local rs = game:GetService("ReplicatedStorage")
--local event = rs.Events.chatEvent
local commands = script.Parent.AdminSystem.Commands:GetChildren() --Gets the folder in which the commands are placed.
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if msg == commands then
print(msg)
end
end)
end)
Your problem is pretty straightforward: Obviously, the msg is not equal to a table of all the commands there are.
What you want to do is check if msg is IN commands, not if msg IS commands (difference between “I am a player of roblox” and “I am roblox” lol)
To check if it is in the table, just do table.find(commands, msg) (It should return a truthy value if it is in there and a falsey value if it isn’t, im too lazy to check what the exact values are but you can just do “if table.find(commands, msg) then stuff”)
Are you sure the commands variable is a table that has a string inside?
local formattedCommands = {}
for _,com in pairs(commands) do
-- Convert it into a string and place it to the table
local comString = com.Value -- If it is a name then change it to com.Name
comString = "/" .. comString -- Add the prefix
table.insert(formattedCommands, comString) -- Placing it into the table
end
and use table.find() to check the command if it is on the table.
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if table.find(formattedCommands, msg) then
print(msg)
end
end)
end)
Yea why is commands a table of objects?
You store the commands in a, well, interesting way, so you have to convert it to a table of strings firsts. I am going to assume that the childrens of script.Parent.AdminSystem.Commands are stringValues and not some other random things, and that the commands are stored in their .Value and not as their name. In that case, simply use a for loop to iterate through the table and replace each object with its string value.
local prefix = "/"
game:GetService("Players").PlayerAdded:Connect(function(player)
player.Chatted:Connect(function(msg)
if string.sub(msg, 1, 1) == prefix then
local command = commands:FindFirstChild(string.split(string.sub(msg, 2, #msg), " ")[1])
print(command)
end
end)
end)
edit: yes i editted this a few times i think i have not gotten enough rest