I want to make the script as efficient and as aesthetic as possible, the issue is that I can’t think of why it doesn’t work just don’t have the energy to keep processing, the idea behind of it is instead of writing a bunch of Indian code making a formula that finds the number string inside of each one of the i.Name and search for it in the table arrays when it matches it’ll process the requested function
-Client side
TeamMenu = M.Parent.Parent.TeamMenu TeamsPack = table.unpack(C.TeamButtons)
for _,i in pairs(TeamMenu:GetDescendants()) do
print(10)
local TeamsUnpacked = TeamsPack[string.match(i.Name,"%d+")]
print(13)
if i:IsA("ImageLabel") and TeamsUnpacked == true then
print(14)
i.TeamName.Text = TeamsUnpacked
end
end
It worked for me to get the number out, but maybe add a few checks:
TeamMenu = M.Parent.Parent.TeamMenu TeamsPack = table.unpack(C.TeamButtons)
for _,i in pairs(TeamMenu:GetDescendants()) do
print(10)
local number = string.gsub(i.Name,"%D", "")
number = tonumber(number)
if number then
local TeamsUnpacked = TeamsPack[number]
print(13)
if i:IsA("ImageLabel") and TeamsUnpacked == true then
print(14)
i.TeamName.Text = TeamsUnpacked
end
end
end
Oh wait, it does return TeamsUnpacked, but it tries to check whether it is true, and not just existent.
TeamMenu = M.Parent.Parent.TeamMenu TeamsPack = table.unpack(C.TeamButtons)
for _,i in pairs(TeamMenu:GetDescendants()) do
print(10)
local number = string.gsub(i.Name,"%D", "")
number = tonumber(number)
if number then
local TeamsUnpacked = TeamsPack[number]
print(13)
if i:IsA("ImageLabel") and TeamsUnpacked then
print(14)
i.TeamName.Text = TeamsUnpacked
end
end
end
Oh, hold on, it’s because you are unpacking the table, (I’m missing a lot and not paying close enough attention.
local TeamMenu = M.Parent.Parent.TeamMenu
local TeamsPack = C.TeamButtons
for _,i in pairs(TeamMenu:GetDescendants()) do
print(10)
local number = string.gsub(i.Name,"%D", "")
number = tonumber(number)
if number then
local TeamsUnpacked = TeamsPack[number]
print(TeamsUnpacked)
print(13)
if i:IsA("ImageLabel") and TeamsUnpacked then
print(14)
i.TeamName.Text = TeamsUnpacked
end
end
end
This could be another cause, but I’m assuming what you wanted was to change the team name under the imagelabel, and if that is what you wanted, there’s nothing wrong with it.
C=require(game:GetService("ReplicatedStorage"):WaitForChild("Configuration"))
-- from the configuration script
TeamButtons = {"TeamName1","TeamName2","TeamName3","TeamName4","TeamName5","TeamName6","TeamName7","TeamName8","TeamName9"};
I’m going to assume the Configurations module returns the TeamButtons, so, it should probably look like this:
local TeamMenu = M.Parent.Parent.TeamMenu
local TeamsPack = C
for _,i in pairs(TeamMenu:GetDescendants()) do
print(10)
local number = string.gsub(i.Name,"%D", "")
number = tonumber(number)
if number then
local TeamsUnpacked = TeamsPack[number]
print(TeamsUnpacked)
print(13)
if i:IsA("ImageLabel") and TeamsUnpacked then
print(14)
i.TeamName.Text = TeamsUnpacked
end
end
end
If it doesn’t only return the TeamButtons, then could I see what exactly it returns? It would help a lot if I could see the layout of what it returns.