Help optimize code

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

3 Likes
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
3 Likes

A small note on this:

I don’t like to tell people why they were kicked. They know, and I’m not going to give them information on how to debug their hacking.

2 Likes

noted

(30 letters :fire::fire::fire: aaaaaaaaaaaaaaaaaaaaaaaa)

2 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.