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")
updateStats[objName].Number:GetPropertyChangedSignal("Value"):Connect(function()
-- 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
end)
end)
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().
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