Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

Players userId won't be added to a table?

Asked by 4 years ago

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:

1local Main = script.Parent.Main
2 
3local WhoFrame = Main.WhoFrame
4local PlrName = game.ReplicatedStorage.PlrName
5 
6Main.WhoFrame.BanButton.MouseButton1Click:Connect(function()
7    PlrName.Value = WhoFrame.PlayerList.Text
8    game.ReplicatedStorage.BanPlayer:FireServer()
9    end)

PlrName is the string and player list is where I type the players name into.

Server script 1:

01local GetList = game.ReplicatedStorage.GetList
02local BanPlr = game.ReplicatedStorage.BanPlayer
03local PlrName = game.ReplicatedStorage.PlrName
04 
05 
06 
07 
08local BanList = {}
09 
10BanPlr.OnServerEvent:Connect(function(player)
11for i, v in pairs(game.Players:GetPlayers()) do
12    if PlrName == v then
13            table.insert(BanList, player.UserId)
14            print("Player is in ban list")
15    end
View all 29 lines...

Server script 2 (detects when the player logs back on)

1local GetList = game.ReplicatedStorage.GetList
2 
3game.Players.PlayerAdded:Connect(function(player)
4    local IsPlayerBanned = GetList:Invoke(player)
5    if IsPlayerBanned == true then
6        player:Kick("You are banned")
7    end
8end)

Thanks for reading!

(Sorry if the code is confusing I followed a manual tutorial and tried to make it automatic)

0
You never actually sent any arguments through :FireServer() :| Ziffixture 6913 — 4y
0
What kind of arguments should I send through FireServer() would things like the player work? TheStarRblx 27 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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:

1BanPlr.OnServerEvent:Connect(function(_,player)
2for i, v in pairs(game.Players:GetPlayers()) do
3    if PlrName == v then
4            table.insert(BanList, player.UserId)
5            print("Player is in ban list")
6    end
7end

Also in your local script the 'MouseButton1Click' seems to never work- at least for me. Try 'MouseButton1Down'.

1Main.WhoFrame.BanButton.MouseButton1Down:Connect(function()
2    PlrName.Value = WhoFrame.PlayerList.Text
3    game.ReplicatedStorage.BanPlayer:FireServer()
4    end)
0
Thanks for the answer, but it still won't work, I added a player:Kick() to the end and it wont kick the player? TheStarRblx 27 — 4y
0
Found another issue I'll just edit my answer CrunchChaotic 139 — 4y
Ad

Answer this question