Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I fix attempt to index nil with 'className'?

Asked by 3 years ago

Hello,

I have a serverscript that doesn't work, and I have no idea why..

I'm trying to revamp an old Minigames game, but I'm not the best at scripting, so here is the code:

minigames = {}

local m = game.ServerStorage.Choices:GetChildren()
for i=1,#m do
    table.insert(minigames, m[i])
    end

things = script.Parent:GetChildren()
for i=1,#things do
    if things[i].className == "TextButton" then
            things[i].Text = minigames[i].Name
    else
        table.remove(things, i)
    end
    if things[i].className == "Script" then
        table.remove(things, i)
    if things[i].className == "UIGridLayout" then
            table.remove(things, i)
            if things[i].className == "BoolValue" then
                table.remove(things, i)
    else
    things[i].MouseButton1Click:Connect(function(clicked)
script.Parent.Name = minigames[i].Name
        print(minigames)
        if  script.Parent.Debounce.Value == false then
            script.Parent.Debounce.Value = true
            game.Workspace.ChosenMinigame.Value = minigames[i].Name
            m = Instance.new("Message")
            m.Parent = game.Workspace
            m.Text = "Someone has chosen " .. script.Parent.Name .. " as the next minigame!"
            wait(3)
            m:remove()
        end
    end)
    end
    end
    end
end

Players.Zweiio.PlayerGui.thing.Frame.Padding.Setup:10: attempt to index nil with 'className'

0
uh would if things[i]:IsA'TextButton' work BulletproofVast 1033 — 3y

1 answer

Log in to vote
0
Answered by 3 years ago

It's Not "className" it's "ClassName"

minigames = {}

local m = game.ServerStorage.Choices:GetChildren()
for i=1,#m do
    table.insert(minigames, m[i])
end

things = script.Parent:GetChildren()
for i=1,#things do
    if things[i].ClassName == "TextButton" then
        things[i].Text = minigames[i].Name
    else
        table.remove(things, i)
    end
    if things[i].ClassName == "Script" then
        table.remove(things, i)
        if things[i].ClassName == "UIGridLayout" then
            table.remove(things, i)
            if things[i].className == "BoolValue" then
                table.remove(things, i)
            else
                things[i].MouseButton1Click:Connect(function(clicked)
                    script.Parent.Name = minigames[i].Name
                    print(minigames)
                    if  script.Parent.Debounce.Value == false then
                        script.Parent.Debounce.Value = true
                        game.Workspace.ChosenMinigame.Value = minigames[i].Name
                        m = Instance.new("Message")
                        m.Parent = game.Workspace
                        m.Text = "Someone has chosen " .. script.Parent.Name .. " as the next minigame!"
                        wait(3)
                        m:remove()
                    end
                end)
            end
        end
    end
end
0
Tell Me If That Works NotConnorRandumb 22 — 3y
Ad

Answer this question