local p = game.Players:FindFirstChild(play[i].Name)
table.insert(insert, 1, p)
This is the section of the code which is incorrect. The format of table.insert is: table.insert (table, [pos,] value), as the wiki exactly says. Both of the tables are dictionaries NOT arrays, this means they use string indexes instead of the usual integer values.
The table.insert function is supposed to insert the value to the end of an array or to the point specified by the 2nd argument if three arguments are present. There is no index of 1, or any number actually, so this won't work. The way to set values in a dictionary is the usual table[key] = value. So that's how you'd set the value instead. Dictionaries are the easier type of table to use, if you use them properly.
So the code I quoted should be this:
insert[play[i].Name] = true
Other things I've noticed:
Pairs only takes one table as an argument, not two, so this could lack its intended functionality.
string.match is intended for patterns like %d+, string.find is much easier and simpler to use (plus it makes sense).
"admins[plr.Name] and true" was probably meant to be admins[plr.Name]==true, so I removed "and true" though you can add it back if you need an extra condition.
You could've used the pairs function for iterating through the GetPlayers table, which is more efficient than using a plain for loop (unless you were planning on ordering them based on a factor of some kind).
Here's your code fixed up for you, you're very welcome :)
Let me know if anything's up, I'm very likely to make a mistake as I'm not checking this in Studio (sorry if there are any indentation issues when pasting into studio).
Cheers :D - CD
local admins = {["Player"] = true,["Player1"] = true,["yougottols1"] = true}
local insert = {}
local commands = {
["/Risen"] = function(message)
print("Success")
end,
["/add"] = function(message)
for _,Player in pairs(game.Players:GetPlayers()) do
if message:find(Player.Name) then
insert[Player.Name] = true
print("YES")
end
end
end,
}
function startsWith(message,starts,forceCaps)
return (forceCaps and message:sub(1,starts:len())==starts or message:lower():sub(1,starts:len())==starts:lower())
end
game.Players.PlayerAdded:connect(function(plr)
plr.Chatted:connect(function(msg)
local function Check(tab,rank)
for i,v in pairs(tab) do
if tab[plr.Name]~=nil then
for index,command in pairs(commands) do
if startsWith(msg,index) then
command(msg)
return true
end
end
end
end
end
for index,adminTable in pairs({admins,insert}) do
if Check(adminTable,index) then
break
end
end
end)
end)
(Sorry if I edited your code too much, just trying to help you as much as possible!)
2 comments
Woah, thank you so much!!!!!!! I will study it to not make the mistake next time, thank you!
You're welcome, happy to help. :D