Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

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

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'

1 comment

0

uh would if things[i]:IsA'TextButton' work

1 answer

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

1 comment

0

Tell Me If That Works

This discussion is preserved as it was. New answers, comments, and votes are closed.