Hello! I am trying to make an adaptable tournament bracket through scripts on a surface gui, but I am having troubles trying to create it.
Basically what I mean is that, for example, when there are 5 players entering the tournament, the gui will scale to fit the screen and show a tournament bracket with those 5 players.
If there are 4 players, the gui will scale accordingly and so on.
I also have another problem, which is the… lines thingy.
Basically this.
The lines that connect to each other. I have no idea how to do that, and this is currently what I have right now.
local cpair = 1
local num = 1
local paired = {}
for i=1, #chars do
local random = chars[math.random(1,#chars)]
repeat random = chars[math.random(1,#chars)] wait() until module.found(paired, random) == false
tournamentbracket[num] = tournamentbracket[num] or {}
tournamentbracket[num][cpair] = random
cpair += 1
if cpair > 2 then cpair = 1 num += 1 end
paired[#paired + 1] = random
end
for i,gui in ipairs(surfacegui:GetChildren()) do
if gui.Name == "List" then
gui:Destroy()
end
end
local sizeScale = (chars-5)
local size = basicSize + (UDim2.new(.05,0,.02,0)*sizeScale)
local a = 1
local b = 1
local c = 1
local d = 1
for i,v in ipairs(chars) do
local humanoid = v:FindFirstChild("Humanoid")
local name = v.Name
if humanoid then name = humanoid.DisplayName end
local list = guiTemplate:Clone()
list.Name = "List"
list.Visible = true
list.Size = size
list.Position += UDim2.new(x,0,list.Position.Y.Scale,0)
list.Text = name
list.Parent = surfacegui
local line = Instance.new("TextLabel")
line.Size = UDim2.new(0.01,0,0.2,0)
a += 1
if a > 2 then a = 1 b += 1 end
if b > 4 then b = 1 c += 1 end
if c > 8 then c = 1 d += 1 end
if d > 12 then d = 1 end
x += .2
end
Some incomprehensible code, so I’ll explain a bit below.
Explanation
So why im looping through the characters is to insert them into the tournamentbracket table, which is how im going to create the gui. Based off of the table. I will first insert a table into the tournamentbracket table and put two characters in there (pairs). This is how I determine who fights against who.
The confusing part is the a b c d part, which is just pairs. I separate tournament brackets into blocks. Like block A has 8 players, block B has 8 players. In the same tournament. So the winner of block A fights block B. Like, block A has 4 and block B has 4. But block A and block B makes up block C, whose winner fights against block D, who also has 8 players. Sorry if my explanation is bad and misleading, but I am honestly bad at explaining that I’ll have to congratulate anyone who even comprehends it.
Any help would be appreciated!