I’m tryna find a clean work around for getting the length of all the texts before setting their sizes. Current problem I have with this is if it does the smallest text first then its size will be its TextSize.X (as it hasn’t done a longer text length yet)
But I don’t wanna just do a for loop twice with the same parameters (TotalMessages.Choices)
Is there a way in the 1 for loop to go through all the text lengths first, then go abouts setting their sizes?
local LongestText = 0
for choice, nextQuery in pairs(TotalMessages.Choices) do
local NewChoice = Choice:Clone()
NewChoice.Text = choice
-- Get choices text size
local TextSize = TextService:GetTextSize(choice, NewChoice.UITextSizeConstraint.MaxTextSize, NewChoice.Font, Vector2.new(Frame.AbsoluteSize.X, Frame.AbsoluteSize.Y))
if TextSize.X > LongestText then
LongestText = TextSize.X
end
-- Set size
NewChoice.Size = UDim2.new(0, LongestText, 0, TextSize.Y)
-- Activated controls
NewChoice.Activated:Connect(function()
NextSpeech = nextQuery
Continue = true
QuestionAsked = false
ChoicesBox.Visible = false
end)
-- Hover effects
local TweenInUnderline = TweenService:Create(NewChoice.Underline, TweenInfo.new(0.25), {Size = UDim2.new(0, TextSize.X, 0, 4)})
local TweenOutUnderline = TweenService:Create(NewChoice.Underline, TweenInfo.new(0.25), {Size = UDim2.new(0, 0, 0, 4)})
NewChoice.MouseEnter:Connect(function()
NewChoice.Arrow.Visible = true
TweenInUnderline:Play()
end)
NewChoice.MouseLeave:Connect(function()
NewChoice.Arrow.Visible = false
TweenOutUnderline:Play()
end)
NewChoice.Parent = ChoicesBox
end