I have a script for manually putting a player in the banlist in ROBLOX Studio, but I'm wondering how I could add people to the banlist in-game using a TextBox.
01 | local BannedList = { |
02 | [ "PlayerX" ] = true ; |
03 | [ "PlayerY" ] = true ; |
04 | [ "PlayerZ" ] = true ; |
05 | } |
06 |
07 | function NewPlayer(pl) |
08 | if BannedList [ pl.Name ] then |
09 | wait() |
10 | pl:Kick(); |
11 | end |
12 | end |
13 |
14 | game.Players.PlayerAdded:connect(NewPlayer) |
15 | table.foreach(game.Players:GetPlayers(), function (i,v) NewPlayer(v) end ) |
First thing to do is Access the players by using the method
, :GetPlayers
.
1 | local players = game.Players:GetPlayers() |
Now that only access the Players, how do we actually access a certain player? By the pairs
function.
1 | local players = game.Players:GetPlayers() |
2 |
3 | script.Parent.FocusLost:connect( function () |
4 | for i,v in pairs ( players ) do |
5 | if script.Parent.Text = = v.Name then |
6 | game.Players:WaitForChild(script.Parent.Text):Kick() |
7 | end |
8 | end |
9 | end ) |
The FocusedLost
event fires when the current TextBox
is unFocused(by pressing the Enter
key)
This might work;
1 | table.insert(BannedList, #BannedList+ 1 , TextBox.Text) |
Just run that right after having gotten input from the textbox.