Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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

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

2 answers

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 comment

1

kicking is easy-yet he wants to know how to ban.

This might work;

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

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

This discussion is preserved as it was. New answers, comments, and votes are closed.