To be honest, I have no idea how I was gonna name this. Still, don't know if that's a good title.
Anyway, I'm making an interview center for a group, and not one of those 1 players GUI application type game, just one of those where you go in, someone interviews you etc. Well, I don't want 10 million people in the same room bothering the two people interviewing. So I'm making a system for that.
So my first question, I made a for i loop, and I did make it right, it posts the textbutton yada yada, but I'm wondering how I post each players name through the loop code:
local players = game.Players:GetChildren() function SetUpNames() gui.Interviewer.SelectPlayer.Size = UDim2.new(1, 0, 0, 500) for i = 1, #players do local playername = Instance.new("TextButton") playername.Name = "PlayerName" playername.Size = UDim2.new(0, 200, 0, 25) playername.Position = UDim2.new(0, 0, 0, (150*i)-150) playername.Text = i --what do i do here? playername.Parent = gui.Interviewer.SelectPlayer end end
Second question, How do I detect when the person clicks on a name? I can't do this manually because 1. I don't know everyone's name 2. The amount of people there will be different every time
I do not have any code because I am 100% clear I have no clue how to do it. I don't even know if it's possible, if it isn't, then I'll think of a new way. Probably would have them enter the name with a text box, then with that name search through all the players?
This is all done in a local script, inside the gui.
Any help would be gladly appreciated.
Questions? Comments? Concerns, make sure to comment and I'll try my best to answer them. -John
You're setting the Text property of the TextButton to the index number of the player.
You're not connecting to the TextButton function (Not necessarily a problem, it just works with my Answer format.)
You do not call the SetUpNames function. I am assuming you execute this function but left it out of our view.
You just need to index the player through the table provided by GetPlayers. Then you would be able to set the property text to the name.
Simple to do, you just connect the variable to the event.
Call the function on the last line of the code.
Get the players while the function is executing. Otherwise it will always return the players who were present when the script was created.
function SetUpNames() local players = game.Players:GetChildren() --Move this variable into the function. Also, use GetPlayers to ensure the object is a player. gui.Interviewer.SelectPlayer.Size = UDim2.new(1, 0, 0, 500) for i = 1, #players do local playername = Instance.new("TextButton") playername.Name = "PlayerName" playername.Size = UDim2.new(0, 200, 0, 25) playername.Position = UDim2.new(0, 0, 0, (150*i)-150) playername.Text = players[i].Name --What is basically happening is the script will get the element at the "i" position in the table. The brackets are another form of indexing of which is useful in this situation. Then we index that object for a name of the player. playername.Parent = gui.Interviewer.SelectPlayer playername.MouseButton1Click:Connect(function() print(playername.Text) print(players[i].Name) --Basically, any variables you used in the for loop can be used in the event function. And they will stick to that button. end) end end SetUpNames() --Call the function.
local players = game.Players:GetChildren() function SetUpNames() gui.Interviewer.SelectPlayer.Size = UDim2.new(1, 0, 0, 500) for i,v in pairs(players) --So you can get the index and value of the player local playername = Instance.new("TextButton") playername.Name = "PlayerName" playername.Size = UDim2.new(0, 200, 0, 25) playername.Position = UDim2.new(0, 0, 0, (150*i)-150) playername.Text = v.Name playername.Parent = gui.Interviewer.SelectPlayer end end