I'm trying to make an admin panel that bans a player when I enter the player name, reason and then press the ban button (gui button) then the players userId should be inserted into a table.
I'm trying to send a string value of the players name to the server script to ban them using a for i, v loop.
Local script code to detect when the button is pressed:
local Main = script.Parent.Main local WhoFrame = Main.WhoFrame local PlrName = game.ReplicatedStorage.PlrName Main.WhoFrame.BanButton.MouseButton1Click:Connect(function() PlrName.Value = WhoFrame.PlayerList.Text game.ReplicatedStorage.BanPlayer:FireServer() end)
PlrName is the string and player list is where I type the players name into.
Server script 1:
local GetList = game.ReplicatedStorage.GetList local BanPlr = game.ReplicatedStorage.BanPlayer local PlrName = game.ReplicatedStorage.PlrName local BanList = {} BanPlr.OnServerEvent:Connect(function(player) for i, v in pairs(game.Players:GetPlayers()) do if PlrName == v then table.insert(BanList, player.UserId) print("Player is in ban list") end end GetList.OnInvoke = function(Player) for i, v in pairs(BanList) do if v == Player.UserId then print("Player Is In The Ban List") return true else print("Player is not in the ban list") return false end end end end)
Server script 2 (detects when the player logs back on)
local GetList = game.ReplicatedStorage.GetList game.Players.PlayerAdded:Connect(function(player) local IsPlayerBanned = GetList:Invoke(player) if IsPlayerBanned == true then player:Kick("You are banned") end end)
Thanks for reading!
(Sorry if the code is confusing I followed a manual tutorial and tried to make it automatic)
OnServerEvent recieves one parameter by default which is the player that ran the event. In your server script 1 you add the player who ran it into the table. You would have to do something like this:
BanPlr.OnServerEvent:Connect(function(_,player) for i, v in pairs(game.Players:GetPlayers()) do if PlrName == v then table.insert(BanList, player.UserId) print("Player is in ban list") end end
Also in your local script the 'MouseButton1Click' seems to never work- at least for me. Try 'MouseButton1Down'.
Main.WhoFrame.BanButton.MouseButton1Down:Connect(function() PlrName.Value = WhoFrame.PlayerList.Text game.ReplicatedStorage.BanPlayer:FireServer() end)