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)