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

Attempt to index a nil value?

I tried editing my script to make it fix, but it doesn't. The script works fine for the first part, but when you click the button after resetting, it pops up 21:04:40.265 - 1 is not a valid member of Frame 21:04:40.265 - Script 'Players.Player1.PlayerScripts.LocalScript', Line 16 21:04:40.266 - Stack End

LAYOUT: https://gyazo.com/97a9cabeb159037bd87f43ef6bf82508

Here is the full script :

repeat wait() until game.Players.LocalPlayer:FindFirstChild("ToolN10")
local player = game.Players.LocalPlayer
local gui = player.PlayerGui.Stats.Frame.Inv
for i=1,10 do
	wait(0.01)
	if player["ToolN"..i].Value == "None" then
		gui[i]["Click"].Disabled = true
	else 
		gui[i].TextButton.Text = player["ToolN"..i].Value
		gui[i]["Click"].Disabled = false
	end
end

player.ToolN1.Changed:connect(function(Change)
	if player.ToolN1.Value == "None" then
		gui["1"]["Click"].Disabled = true
	else
		gui["1"].TextButton.Text = player.ToolN1.Value
		gui["1"]["Click"].Disabled = false
	end
end)
player.ToolN2.Changed:connect(function(Change)
	if player.ToolN2.Value == "None" then
		gui["2"]["Click"].Disabled = true
	else
		gui["2"].TextButton.Text = player.ToolN2.Value
		gui["2"]["Click"].Disabled = false
	end
end)
player.ToolN3.Changed:connect(function(Change)
	if player.ToolN3.Value == "None" then
		gui["3"]["Click"].Disabled = true
	else
		gui["3"].TextButton.Text = player.ToolN3.Value
		gui["3"]["Click"].Disabled = false
	end
end)
player.ToolN4.Changed:connect(function(Change)
	if player.ToolN4.Value == "None" then
		gui["4"]["Click"].Disabled = true
	else
		gui["4"].TextButton.Text = player.ToolN4.Value
		gui["4"]["Click"].Disabled = false
	end
end)
player.ToolN5.Changed:connect(function(Change)
	if player.ToolN5.Value == "None" then
		gui["5"]["Click"].Disabled = true
	else
		gui["5"].TextButton.Text = player.ToolN5.Value
		gui["5"]["Click"].Disabled = false
	end
end)
player.ToolN6.Changed:connect(function(Change)
	if player.ToolN6.Value == "None" then
		gui["6"]["Click"].Disabled = true
	else
		gui["6"].TextButton.Text = player.ToolN6.Value
		gui["6"]["Click"].Disabled = false
	end
end)
player.ToolN7.Changed:connect(function(Change)
	if player.ToolN7.Value == "None" then
		gui["7"]["Click"].Disabled = true
	else
		gui["7"].TextButton.Text = player.ToolN7.Value
		gui["7"]["Click"].Disabled = false
	end
end)
player.ToolN8.Changed:connect(function(Change)
	if player.ToolN8.Value == "None" then
		gui["8"]["Click"].Disabled = true
	else
		gui["8"].TextButton.Text = player.ToolN8.Value
		gui["8"]["Click"].Disabled = false
	end
end)
player.ToolN9.Changed:connect(function(Change)
	if player.ToolN9.Value == "None" then
		gui["9"]["Click"].Disabled = true
	else
		gui["9"].TextButton.Text = player.ToolN9.Value
		gui["9"]["Click"].Disabled = false
	end
end)
player.ToolN10.Changed:connect(function(Change)
	if player.ToolN10.Value == "None" then
		gui["10"]["Click"].Disabled = true
	else
		gui["10"].TextButton.Text = player.ToolN10.Value
		gui["10"]["Click"].Disabled = false
	end
end)

Character Added Script:

game.Players.LocalPlayer.CharacterAdded:connect(function(Add)
	local player = game.Players.LocalPlayer
	local gui = player.PlayerGui.Stats.Frame.Inv
	repeat wait() until game.Players.LocalPlayer.PlayerGui.Stats.Frame.Inv:FindFirstChild("10")
for i=1,10 do
	if player["ToolN"..i].Value == "None" then
		gui[i]["Click"].Disabled = true
	else 
		gui[i].TextButton.Text = player["ToolN"..i].Value
		gui[i]["Click"].Disabled = false
	end
end
end)

2 answers

✓ Accepted answer
player.ToolN3.Changed:connect(function(Change)
    if Change == "None" then
        gui:FindFirstChild("3")["Click"].Disabled = true
    else
        gui:FindFirstChild("3").TextButton.Text = player.ToolN3.Value
        gui:FindFirstChild("3")["Click"].Disabled = false
    end
end)

This function seems to have your issue. Specifically, one of these two lines below:

       gui:FindFirstChild("3").TextButton.Text = player.ToolN3.Value

or;

     gui:FindFirstChild("3")["Click"].Disabled = true

Usually the debug statement "Attempting to index a nil value" is pretty self explanatory. You tried to screw with a value that is literally non-existent.

So your best chance is to figure out what the two lines of code I listed above are doing to your script and why they are considered non-existent. You didn't provide much context on these two lines of code, so this is my best answer.

6 comments

0

What else would you like so you can see all of the context?

0

There are no errors anymore with the :WaitForChild, but now the text isn't getting changed.

0

It is waiting for a value that is existent.

0

I would like to know if ToolN3.Value is the Value of a Value named ToolN3 or is just the directory leading to a Value. If Value is the name of the Value, say Value.Value for the directory, as you're only indexing the name and not the Value property of the Value.

0

ToolN3 is a StringValue

0

I'm going to have to go further into this by checking each object involved in the script, which will probably take forever. (Time I don't have.) .. Sorry, I tried my best. Try some solutions in your head, maybe one of them will solve your issue :)

By the looks of things, gui['3'] doesn't exist. Your error doesn't quiet line up with your code, so I've taken my closest guess.

If in doubt, use WaitForChild.

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