Players userId won't be added to a table?
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:
1 | local Main = script.Parent.Main |
3 | local WhoFrame = Main.WhoFrame |
4 | local PlrName = game.ReplicatedStorage.PlrName |
6 | Main.WhoFrame.BanButton.MouseButton 1 Click:Connect( function () |
7 | PlrName.Value = WhoFrame.PlayerList.Text |
8 | game.ReplicatedStorage.BanPlayer:FireServer() |
PlrName is the string and player list is where I type the players name into.
Server script 1:
01 | local GetList = game.ReplicatedStorage.GetList |
02 | local BanPlr = game.ReplicatedStorage.BanPlayer |
03 | local PlrName = game.ReplicatedStorage.PlrName |
10 | BanPlr.OnServerEvent:Connect( function (player) |
11 | for i, v in pairs (game.Players:GetPlayers()) do |
13 | table.insert(BanList, player.UserId) |
14 | print ( "Player is in ban list" ) |
18 | GetList.OnInvoke = function (Player) |
19 | for i, v in pairs (BanList) do |
20 | if v = = Player.UserId then |
21 | print ( "Player Is In The Ban List" ) |
24 | print ( "Player is not in the ban list" ) |
Server script 2 (detects when the player logs back on)
1 | local GetList = game.ReplicatedStorage.GetList |
3 | game.Players.PlayerAdded:Connect( function (player) |
4 | local IsPlayerBanned = GetList:Invoke(player) |
5 | if IsPlayerBanned = = true then |
6 | player:Kick( "You are banned" ) |
Thanks for reading!
(Sorry if the code is confusing I followed a manual tutorial and tried to make it automatic)