Attempt to index nil problem


I am stuck with this problem for a while now and I cannot find the issue. Can you please help me solve this problem?

I am trying to change a text when The Value Changes, but I keep getting the Error saying that I index nothing with that Text property.

game:FindFirstChild("ReplicatedStorage"):FindFirstChild("updateText").OnServerEvent:Connect(function(player, objName)
	local updateStats = player:FindFirstChild("Inventory")

-- The Error says that I am indexing nil with that .Text, but everything is correct

		objName.ProgressBar.ProgressBarText.Text = updateStats[objName].Number.Value.." / "..updateStats[objName].MaxNumber.Value



is objName a string? try making it an instance

On this line right there

objName.ProgressBar.ProgressBarText.Text = updateStats[objName].Number.Value.." / "..updateStats[objName].MaxNumber.Value

When you try to index it with a ProgressBarText, which doesn’t exist on the ProgressBar, it could be either named differently, or no instance of it at all. My solution is that I could either add FindFirstChild or WaitForChild inside of the ProgressBarText, just so it can find better, or tell if it’s missing or not.
Hopefully it solves it!

That is just as example. I tried to index it directly as instance and is just not working. The thing is that I clone that Inventory to a scrolling frame. But the problem that I don’t understand is why I get it nil if the value is changing only after some things happen. I don’t think that is a loading problem.

Attempt to index nil essentially means that you are trying to access something, on an item that does not exist. (ex: Attempting to access the Color Property, on an object that does not yet exist (aka nil meaning “no value”))

Most of the Time, its a loading issue on the Clients behalf, considering it takes time to copy everything, which is why its recommended you wait for the items prior to firing any code to ensure no errors using :WaitForChild(), or use Sanity Checks, to validate its existence using :FindFirstChild().

1 Like

I tried, but not working. I get the same problem no matter what I am doing. Thanks for replying!

Can you show a screenshot of the explorer showing the objects shown in the script?

I didn’t spell anything wrong. Studio autocomplete it for me :slight_smile:

We’re gonna need a screenshot of the explorer so we can see the ancestral heirarchy and make sure you haven’t written any of the indexes wrong.

If I put the whole thing in local script as the path I don’t get the error, but the text not being updated.
I guess it has to do with the fact that I am Cloning that Inventory Slot and may be some delay. But I change the values manually for now and I don’t think that the Inventory is not cloned, because I can see it cloned visually on my screen. If I print out the objName.Text after I change the values, it prints me out the correct values but not showing them on screen.

local objName = script.Parent.etc.Text -- If I type it in Local Script like this is not giving me the error, but the text is not changing

I solved it by placing the code in the script where I clone the Inventory so the changes happen when its cloned and not after.

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