Hello,
I need help optimizing the block of code below I wrote, as it looks unnescesarily complicated.
if reason == "kick" then
if info[3] then
local kicked_player = table.remove(info, 1)
local reason = table.concat(info, " ")
for _, v in next, game.Players:GetPlayers() do
if string.lower(v.Name) ~= string.lower(info[1]) and string.lower(v.Name) == string.lower(kicked_player) then
v:Kick(reason)
end
end
else
for _, v in next, game.Players:GetPlayers() do
if string.lower(v.Name) == string.lower(info[1]) then
v:Kick(info[2])
end
end
end
to optimise you can use variables for values called for more than once, and for example also using the Player service. If you want to make it look less complicated use the string metamethods, but i think the string library is alot faster. You also do not need to use next anymore in a i, v loop
if reason == "kick" then
local kicked_player = table.remove(info, 1)
local kick_reason = table.concat(info, " ")
for _, v in ipairs(game.Players:GetPlayers()) do
if string.lower(v.Name) == string.lower(kicked_player) then
v:Kick(kick_reason)
break
end
end
end