Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Why is my script not working?

My ban script command for in game use when I perform a command (/ls CODE BELOW) I am meant to be able to use /b PLAYER'S-FULL-NAME to ban them but every time I launch the script I crash. Does anyone know how to stop this? Below is the script I use:

bans = {}

game.Players.LocalPlayer.Chatted:connect(function(ban)
if ban:lower():sub(1,3) == "/b " then
plr = ban.sub(ban,4)
player = game.Players:FindFirstChild(plr)
if player ~= nil then
table.insert(bans,plr)
player:remove()
end
end
end)

while true do
for i,v in pairs(game.Players:GetPlayers()) do
for j,k in pairs(bans) do
if k == v.Name then
v:remove()
end
end
end
end

1 answer

✓ Accepted answer

At line 14 you have a while loop which would crash your game. To prevent this try adding a wait() like this...

bans = {}

game.Players.LocalPlayer.Chatted:connect(function(ban)
if ban:lower():sub(1,3) == "/b " then
plr = ban.sub(ban,4)
player = game.Players:FindFirstChild(plr)
if player ~= nil then
table.insert(bans,plr)
player:remove()
end
end
end)

while true do
wait()
for i,v in pairs(game.Players:GetPlayers()) do
for j,k in pairs(bans) do
if k == v.Name then
v:remove()
end
end
end
end

This discussion is preserved as it was. New answers, comments, and votes are closed.