Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why is my script not working?

Asked by 10 years ago

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

Log in to vote
0
Answered by 10 years ago

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
Ad

Answer this question