VIP Server Ban Command Help

Hello there fellow programmers! Recently I have decided to try and make a server ban command for VIP server owners for my game. Meaning that the owner of a VIP server can ban someone from their VIP server so they cannot join back. This is NOT a full game ban. Something to note before responding is that we have a custom chat on our game so that is why some of the pickups like on chat is not using Roblox standard events.

So what I need help with here is figuring out why the player is not kicked upon rejoining. The command works successfully as it does kick the player and it functions correctly. I just need to know why they are not kicked upon rejoining. Get back to me when you can. Thanks!

Script:

local VIPID = game.PrivateServerId
local banned = {}

function getClosestPlayerMatch(name)

	-- Find and return the player
	local plr = nil
	for _, i in pairs(game.Players:GetPlayers()) do
		if string.sub(i.Name, 1, string.len(name)) == name then
			plr = i
			break
		end
	end
	return plr

end

game.ReplicatedStorage.Interactions.Server.SendChatMessage.OnServerEvent:Connect(function(plr, msg)
	local plrName = ""
	if string.sub(msg, 1, 1) == "/" then
		if string.sub(msg, 2, 10) == "serverban" and VIPOwner == plr.UserId then
			local otherPlr = getClosestPlayerMatch(plrName)
			if otherPlr ~= nil then
				table.insert(banned, otherPlr.Name)
				otherPlr:Kick("You have been banned from " .. plr.Name .. "'s VIP server. You are NOT banned from the entire game.")
			else
				game.ReplicatedStorage.Interactions.Client.ShowChatMessage:FireClient(plr, nil, "Kicking error! You must likely entered an invalid player.", Color3.fromRGB(255, 0, 0))
			end
		end
	end
end)

game.Players.PlayerAdded:Connect(function(plr)
	if table.find(banned, plr.Name) then
		plr:Kick("You have been banned from " .. plr.Name .. "'s VIP server. You are NOT banned from the entire game.")
	end
end)
2 Likes

Are you certain that your PlayerAdded event runs at all?
Here’s what I recommend doing, in case of delays, etc etc.

local Players = game:GetService('Players')
local Banned = {}


local function PlayerAdded(Player)
	if table.find(Banned, Player.Name) then
		Player:Kick('Banned from this server.')
	end
end


local GetPlayers = Players:GetPlayers()
for i = 1, #GetPlayers do
	coroutine.resume(coroutine.create(function()
		PlayerAdded(GetPlayers[i])
	end))
end
Players.PlayerAdded:Connect(PlayerAdded)

The game can sometimes be laggy for some users upon join followed by our loading screen which can take a few seconds. I’ll try the script out and see how it goes.

Yeah, try my code and see if it makes any difference.

Do you think DataStore would be better for this?