local function displayPlayers()
plrList.Visible = true
for _, player in pairs(players:GetChildren()) do
local tag = plrList:FindFirstChild('PLRTAG'):Clone()
tag.Visible = true
tag.TextButton.Text = player.Name
tag.Parent = plrList
tag.TextButton.Activated:Once(function()
print('Player pressed!'..player.Name)
plrList.Visible = false
-- remove items in plrList
for _, item in pairs(plrList:GetChildren()) do
if item:IsA('Frame') then
item:Destroy()
end
end
-- send back player name
return player
end)
end
end
as you can see in the script there is a return. This return comes once a player presses on a button.
Now where I call that script I need to make it so the script waits until the Value is returned.
Anyway to do this?
If you dont need the players to click the same button twice then you could do it like this
local function displayPlayers()
plrList.Visible = true
for _, player in pairs(players:GetChildren()) do
local tag = plrList:FindFirstChild('PLRTAG'):Clone()
tag.Visible = true
tag.TextButton.Text = player.Name
tag.Parent = plrList
tag.TextButton.Activated:Wait()
print('Player pressed!'..player.Name)
plrList.Visible = false
-- remove items in plrList
for _, item in pairs(plrList:GetChildren()) do
if item:IsA('Frame') then
item:Destroy()
end
end
-- send back player name
return player
end
end
local function displayPlayers()
local playerSelected = Instance.new("BindableEvent")
plrList.Visible = true
for _, player in pairs(players:GetChildren()) do
local tag = plrList:FindFirstChild('PLRTAG'):Clone()
tag.Visible = true
tag.TextButton.Text = player.Name
tag.Parent = plrList
tag.TextButton.Activated:Connect(function()
print('Player pressed!'..player.Name)
plrList.Visible = false
for _, item in pairs(plrList:GetChildren()) do
if item:IsA('Frame') then
item:Destroy()
end
end
-- signal that a player has been selected
playerSelected:Fire(player.Name)
end)
end
-- wait for a player to be selected
local selectedPlayerName = playerSelected.Event:Wait()
playerSelected:Destroy()
-- return the selected player's name
return selectedPlayerName
end
The reason I have it in a function is cause I am going to use it multiple times, anyhow I dont see how this could be a bad thing(Personal me) But I think what @syxnlucas said will work