"Index functin with long name"

this keeps happening its so absolutely annoying man

local Container = script.Parent.Parent
local MainSettings = Container.Main.Main.Main.Placeholder
local Module = require(script.Parent.Parent.Parent.Parent:WaitForChild("TeamsModule"))
local Selection = Container.Selection.Dropdown

local Service = game:GetService("TweenService")
local Info = TweenInfo.new(0.3, Enum.EasingStyle.Quint)

local servername = game:GetService("ReplicatedStorage"):WaitForChild("ModifiedEuropeanFootball"):WaitForChild("ServerName")

local function clickedPage(button, frame)
    game.Players.LocalPlayer.PlayerGui.Sounds.Enter:Play()
    
    for _,v in pairs(MainSettings:GetDescendants()) do
        if v:IsA("ScrollingFrame") then
            if v.Name ~= "PinHolder" then
                v.Visible = false
            end
        end
    end
    
    for _,v in pairs(Selection:GetChildren()) do
        if v:IsA("TextButton") then
            for i,e in pairs(Module) do
                v.BackgroundColor3 = Color3.fromRGB(39, 39, 39)
                v.TextColor3 = Color3.fromRGB(255,255,255)
                if servername.Value == e.longname or servername.Value == e.shortname then
                    v.BackgroundColor3 = e.color
                    v.TextColor3 = e.text
                end
            end

        end
    end
    
    frame.Visible = true 
end

Module

local Teams = {
    {longname = "liverpool", shortname = "lfc", color = Color3.fromRGB(255, 70, 73), imageid = "13177895312", league = "PL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "bayern", shortname = "bay", color = Color3.fromRGB(255, 70, 73), imageid = "15284254641", league = "BL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "manchester united", shortname = "mun", color = Color3.fromRGB(255, 70, 73), imageid = "14540294821", league = "PL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "barcelona", shortname = "fcb", color = Color3.fromRGB(1, 103, 255), imageid = "12303925910", league = "LL", text = Color3.fromRGB(255,255,255)},
}
function Teams.getImg(imgid)
    return "rbxthumb://type=Asset&id="..imgid.."&w=420&h=420"
end

return Teams

Please elaborte more, what issue do you get and what do you want to achieve?

I just explained to you
“Index function with long name”

this is a module of 3 football teams
and if the servername value is like one of their long names or short names

they get custom user interface theme

but i keep getting this error even if i put wait for childs, repeat wait until, task.wait

The module script that is returned should have a structure of this:

Teams = {
 {longname = "liverpool", shortname = "lfc", color = Color3.fromRGB(255, 70, 73), imageid = "13177895312", league = "PL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "bayern", shortname = "bay", color = Color3.fromRGB(255, 70, 73), imageid = "15284254641", league = "BL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "manchester united", shortname = "mun", color = Color3.fromRGB(255, 70, 73), imageid = "14540294821", league = "PL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "barcelona", shortname = "fcb", color = Color3.fromRGB(1, 103, 255), imageid = "12303925910", league = "LL", text = Color3.fromRGB(255,255,255)},
getImg = function(imgid)
return "rbxthumb://type=Asset&id="..imgid.."&w=420&h=420"
end
}

WIth this you are looping through each value in the table, including the function getImg, thus the error "attempt to index function (which is the getImg function) with longname (?). You need to seperate the tables in the module like this:

local Teams = {
Teams = { -- put a teams table in the module so it doesn't conflict with the function
    {longname = "liverpool", shortname = "lfc", color = Color3.fromRGB(255, 70, 73), imageid = "13177895312", league = "PL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "bayern", shortname = "bay", color = Color3.fromRGB(255, 70, 73), imageid = "15284254641", league = "BL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "manchester united", shortname = "mun", color = Color3.fromRGB(255, 70, 73), imageid = "14540294821", league = "PL", text = Color3.fromRGB(255,255,255),  invertbar = false},
    {longname = "barcelona", shortname = "fcb", color = Color3.fromRGB(1, 103, 255), imageid = "12303925910", league = "LL", text = Color3.fromRGB(255,255,255)},
}
}
function Teams.getImg(imgid)
    return "rbxthumb://type=Asset&id="..imgid.."&w=420&h=420"
end

return Teams

Then in the script, you loop through the Teams table inside of the module instead of the entirety of it:

for _,v in pairs(Selection:GetChildren()) do
        if v:IsA("TextButton") then
            for i,e in pairs(Module.Teams) do -- access Teams table in the module
                v.BackgroundColor3 = Color3.fromRGB(39, 39, 39)
                v.TextColor3 = Color3.fromRGB(255,255,255)
                if servername.Value == e.longname or servername.Value == e.shortname then
                    v.BackgroundColor3 = e.color
                    v.TextColor3 = e.text
                end
            end

        end
    end

1 Like

You have to check the servername.Value to the longname and shortname

for _,v in pairs(Selection:GetChildren()) do
        if v:IsA("TextButton") then
            for _, team in pairs(Module.Teams) do
                if servername.Value == team.longname or servername.Value == team.shortname then
                    v.BackgroundColor3 = team.color
                    v.TextColor3 = team.text or Color3.fromRGB(255,255,255) -- default color if it doesnt exist
                end
            end
        end
    end
    
    frame.Visible = true 

… what am i doing then? showing off

Ill try doing this in a second

much love, only if I knew this when i started doing tables

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.