I’m trying to create a player records search GUI, and I’m using a ScrollingFrame coupled with a script that creates a new TextLabel for each name in the dropdown.
This is the code behind it:
function makeButton(player)
scrollingFrame.Visible = true
local newButton = Instance.new("TextButton",scrollingFrame)
newButton.Size = UDim2.new(0, 175 ,0, 25)
newButton.BackgroundColor3 = Color3.fromRGB(56, 142, 60)
newButton.TextColor3 = Color3.fromRGB(255,255,255)
newButton.BackgroundTransparency = 0
newButton.BorderSizePixel = 0
newButton.Font = "SourceSans"
newButton.Text = player.Name
newButton.TextSize = 18
newButton.ZIndex = 4
newButton.Name = "LookupButton"
local newScript = script.Parent.PlayerClickCopy:Clone()
newScript.Parent = newButton
newScript.Disabled = false
end
function makeButtonsFromPlayers(players,length,lookUpString)
if string.lower(string.sub(players.Name,1,length)) == string.lower(lookUpString) then
if players.name == lookUpString then
scrollingFrame.Visible = false
else
makeButton(players)
end
end
end
textBox:GetPropertyChangedSignal("Text"):connect(function()
removeOldButtons()
local lookUpString = textBox.Text
local children = game.Players:GetPlayers()
local length = string.len(lookUpString)
for _,players in pairs(children) do
if textBox.Text == "" then
scrollingFrame.Visible = false
break
else
makeButtonsFromPlayers(players,length,lookUpString)
end
end
end)
When I type in “A”, and there’s more than one person whose name begins with “A” in game, it creates two labels, but doesn’t set Position properly. I can’t figure out how I should increment Position to make it show labels separately.
My aim here is advice on how to set position for each label so that as I scroll, each name is displayed separately, not all on each other.