:Kick() function not working

So I have this code:

commands.serverban = function(sender, arguments)
	local player = findPlayer(arguments[1], sender)
	
	if not table.find(serverBannedPlayers, player.Name) and player.Name ~= "SpySethy" then
		player:Kick("you are banned from this server")
		
		table.insert(serverBannedPlayers, player.Name)
	end
end

and the :Kick() function does not seem to be kicking my friend out of the game. Can anyone help with this?

1 Like

Well does player even exist in the first place? What’s findPlayer?

Where is the script located in your game (ServerScriptService, StarterGui, etc)?

Also, as @weakroblox35 pointer out, there isn’t a direct mention to findPlayer, so that is going to be part of your issue. You can try using this update to your script, that finds the player.

commands.serverban = function(sender, arguments)
    local playerName = table.concat(arguments, " ", 1)
    local player = game.Players:FindFirstChild(playerName)

    if player and not table.find(serverBannedPlayers, player.Name) and player.Name ~= "SpySethy" then
        player:Kick("You are banned from this server")
        table.insert(serverBannedPlayers, player.Name)
    elseif not player then
        sender:SendMessage("Player not found.")
    end
end

Thats a function I created here it is:

local function findPlayer(name, sender)
	if name == "me" then
		return sender
	else
		for i, player in pairs(game.Players:GetPlayers()) do
			if string.lower(player.Name) == name then
				return player
			end
		end
		
		return nil
	end
end

Thanks that helped it now bans me from the server.

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