ik there is a banned string and all but the banned string for some reason wont ban the players its as if I don't have a string there at all there a fix to this or a line I need to add?
local speakers = {"skillfulzombie88"}
local banned = {""}
local function checkSpeakers(name)
for _,speaker in pairs(speakers) do
if name:lower() == speaker:lower() then return true
end
end
return false
end
local function banPlayer(banner, victim)
if victim ~= banner then
victim:Destroy()
banned[victim.Name] = victim.Name
end
end
local function matchPlayer(str)
local result = nil
local players = game.Players:GetPlayers()
for _, player in pairs(players) do
if player.Name:lower():find(str) == 1 then
--Abort if two players match the string
if result then return end
result = player
end
end
return result
end
local function onChatted(msg, speaker)
-- split command into the first word and the remaining words
local cmd, args = msg:lower():match("(%w+) (.+)")
if cmd == "ban" then
-- words and numbers
for word in args:gmatch("%w+") do
local p = matchPlayer(word)
if p then
banPlayer(speaker, p)
end
end
end
end
local function onPlayerEntered(newPlayer)
-- remove banned player if they try to come back in
for _, v in pairs(banned) do
if v:lower() == newPlayer.Name:lower() then
newPlayer:Destroy()
end
end
if checkSpeakers(newPlayer.Name) then
newPlayer.Chatted:connect(function(msg, recipient)
onChatted(msg, newPlayer)
end)
end
end
game.Players.PlayerAdded:connect(onPlayerEntered)
