Still have questions? Join our Discord server and get real time help.
3

# How do I add a player to a table in a script when a TextBox contains their name?

Asked by 5 years ago

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.

local BannedList = {
["PlayerX"] = true;
["PlayerY"] = true;
["PlayerZ"] = true;
}

function NewPlayer(pl)
if BannedList[pl.Name] then
wait()
pl:Kick();
end
end

table.foreach(game.Players:GetPlayers(), function(i,v) NewPlayer(v) end)


1
woodengop 1127
5 years ago

First thing to do is Access the players by using the method, :GetPlayers.

local players=game.Players:GetPlayers()


Now that only access the Players, how do we actually access a certain player? By the pairs function.

local players=game.Players:GetPlayers()

script.Parent.FocusLost:connect(function()
for i,v in pairs( players ) do
if script.Parent.Text==v.Name then
game.Players:WaitForChild(script.Parent.Text):Kick()
end
end
end)


The FocusedLost event fires when the current TextBox is unFocused(by pressing the Enter key)

1
kicking is easy-yet he wants to know how to ban. unmiss 337 — 5y
1
saenae 318
5 years ago

This might work;

table.insert(BannedList, #BannedList+1, TextBox.Text)


Just run that right after having gotten input from the textbox.