I’m just going to answer your question: It returns nil because the table does not have a value that correlates to the key. This can be because of many factors; the table can be modified during runtime, val
's name is incorrect, etc. It’s extremely difficult to debug someone else’s code without direct access to the environment.
This is something I covered in the original post.
These prints all happened both before and after the if
statement, and always within the function. Therefore, there is no change within the code. There is something else going on.
I do have the .rblx file of the game, and while I’d rather not, I could just post it here if the problem got too hard to fix without direct access to the environment, like you said. Or I could just message anyone who wanted the file individually, I’d probably be more comfortable with that. Either way, I’d be willing to share the file if stuff gets too bad.
There’s literally zero way you can say otherwise to the fact that your table does not contain the key you’re indexing. LuaU doesn’t simply throw nil
at you because it feels like it. The table does not have the value for the key, period.
If you do want to share the .rblx file of the game in PM’s, I’ll be happy to check it out and fix it.
Ok, so as @Dan_PanMan found, apparently it was the tonumber(val.Name)
thing. I don’t know why it wasn’t working earlier, I don’t know why it works now, but it does.
nice