Why does the error code giving incorrect information?

This post is old and made when I was extremely young and didn’t know anything of the time. This is basically the question and the solution:

player.leaderstats.Stages = 0

Stages in this scenario is a IntValue, which I assigned it to 0 which was a mistake on my part. But the error instead of telling it’s illegal or invalid, it decided to say that Stages is not a valid member of the leaderstats - which is false because the Stages - is indeed inside of the leaderstats.

The reason why this happens is that Lua thought Stages is a property inside the leaderstats and not a member inside the explorer, and properties are members aswell. Which gives:

Stages is not a valid member of Folder "game.Players.Xapelize.leaderstats"

Old post:

In a line of ServerScript, I did a little code mistake:

player.leaderstats.Stages = 0

And it gives the following error in this script:

Stages is not a valid member of Folder "game.Players.Xapelize.leaderstats"

For your information, Stages is an IntValue

I checked the script, and checked does Stages exists in server-sided when testing, so I was very confused so I made a script:

print(player:FindFirstChild("leaderstats"):FindFirstChild("Stages") ~= nil)

And, the result is false. After I realizing my code mistake, I changed it to this:

player.leaderstats.Stages.Value = 0

And it works perfectly fine. But, why the error code says Stages is not a valid member of leaderstats even Stages is inside leaderstats? The error code should be “Attempt to perform arithmetic on number and Instance”. Can anybody explain?

Oh by the way, tell me if the category is wrong, because I don’t see any “Roblox Studio bugs” in it. Thanks for reading :wink:

It thinks that “Stages” is a property of “leaderstats”, and properties technically seem to be “members” of instances.

1 Like

Nope, it’s constructed by an Instance.new function and no attributes was inside when I checked it. Thanks for answering too!!

Did you mean that it couldn’t interpret “Stages” as a property because it’s an instance? If you did, then maybe this is popping up because of how Lua interpreter works:

workspace.foo = "bar"
--        ^ there is nothing after "foo", it's a member (property) of workspace (the previous word) then
--OH WAIT LOL THIS PROPERTY DOESN'T EXIST IMMA THROW AN ERROR
workspace.foo.Value = "bar"
--             ^ there is nothing after "Value", it's a member (property) of foo (the previous word) then

If that’s how it works, then it explains everything - interpreter will always interpret the last word of the path as a member (property) of the previous word, and since “foo” isn’t a property of Workspace it will throw that the member doesn’t exist.
If the interpreter doesn’t work like that, damn those who are above us.
Sorry if this sounds too technical.

1 Like

I don’t really understand but I will mark this as a solution for now! I’ll check back tomorrow to see if I understand…