✓ Accepted answer
#Four Things
- Your code was not formatted. Format. Your. Code. It's proper practice and makes spotting errors easier.
- You were removing a
string. You needed to remove the Player. You were using variable plr not player. I fixed that for you.
- Your
remove() line was inside of the if plr ~= bans[i] then block, which was inside your for loop. You would have noticed this if you had formatted your code.
- You were adding the
plr string everytime there was already a string in the bans table that WASN'T equal to plr. I'm assuming this was just a small mistake, but your script wouldn't have worked. Now, I'm just checking to see if the player is already banned. At the end of the loop, if they are not banned yet, I am banning them by putting their name into the array.
###Here is the working script
bans = {}
game.Players.LocalPlayer.Chatted:connect(function(ban)
if ban:lower():sub(1,3) == "/b " then
plr = ban:sub(4)
player = game.Players:FindFirstChild(plr)
if player ~= nil then
player:Kick()
local bannedAlready = false
for i = 1, #bans do
if plr == bans[i] then
bannedAlready = true
break
end
end
if not bannedAlready then
table.insert(bans,plr)
end
end
end
end)
game.Players.PlayerAdded:connect(function(plr)
for i = 1, bans do
if plr.Name == bans[i] then
plr:Kick()
end
end
end)
FORMAT YOUR CODE!!!
EDITS
I edited my code to improve it a little bit.
2 comments
I suggest you to use the Markdown ordered list for formatting the answer as the site supports that.
Thank you, @gskw, for the tip!!