The issue is that you have all of those blank strings ("") in your restricted table. The absence of a character will make string.find true for any string if you try to find a blank string.
Another issue is this bit:
if p.Name ~= fulladmins[i] then
What this does is check if the player who chatted's name isn't equivalent to the current fulladmin that's being "viewed" by the for loop. However, what if the admin is in the admins list, but hasn't been iterated yet?
Here's a fixed version of your script;
local admins = {"fireboltofdeath","adorablegirl1998"}
local Restricted = {":give"}
game.Players.PlayerAdded:connect(function(p)
p.Chatted:connect(function(c)
local isAdmin = false
for _, admin in pairs(admins) do
if p.Name == admin then
isAdmin = true
break
end
end
if not isAdmin then
for _, restricted in ipairs(Restricted) do
if string.find(string.lower(c), string.lower(restricted)) then
spawn(function()
m = Instance.new("Message", workspace)
m.Text = "ALERT! ALERT!"
wait(1.5)
m.Text = "Access Restricted, kicking player: " .. p.Name
wait(0.5)
p:Kick()
wait(1.5)
m.Text = "Restricted Command Used: " .. restricted
wait(1.5)
m:Destroy()
end)
break
end
end
end
end)
end)
Here's what changed: First, we removed all of the extra contents of Restricted. We also made Restricted a local variable, which is a good practice.
Next, rather than iterating through the admins in an incorrect way, we do this...
local isAdmin = false
for _, admin in pairs(admins) do
if p.Name == admin then
isAdmin = true
break
end
end
... to determine whether the player is an admin or not.
Then, we check here...
if not isAdmin then
... if they aren't an admin. If they aren't an admin, we proceed.
We then loop through the restricted words, checking if they're restricted.
If the word is restricted, we do some magical stuff and use "break" to exit out of the for loop. We already kicked the player; there's no need to see if they used another restricted word.
A key change I made is that rather than using numerical iteration, where you loop through lists and get the value of the iteration using an index, we can simply iterate through the list without using numbers in this format:
for index, value in pairs(table) do
end
Since we don't use the variable index in both of the cases where we use this type of for-loop, we just use the variable name _, which is conventional for an unused variable. We also name the value variable appropriately for whatever we're doing in the for loop.
Finally, note how in the restricted for loop, we use ipairs. ipairs functions just like pairs, except it makes sure to iterate through a table in the same order as the table was created.
Hope this helped. Good luck!
1 comment
And it says no errors in the output. Every single time I checked