Identical Scripts. One works, the other doesn't

Here’s the script that works;
image
This successfully prints “test” when one of the values changes.

This, script, however doesn’t work;
image

I’ve been struggling with this for a while now, just don’t get it.
I even copy & pasted it into a new game, it didn’t work in the new game. Doesn’t make sense?

1 Like

Could you show some specific instances of changes you make to the tables in which it doesn’t print anything?

PS: You shouldn’t store data with the key as username in the same table as where you keep the methods of the module. What if someone joins with “AddPlayer” as username, or any other name you use as a method? It’d be overridden by PlayerData[PlayerName] = {}, and then you’re in trouble. Use a different table to store the player data, or reference them by the userid / player object.

1 Like

PlayerStats[PlayerName].TheStats.Mobux = 5929
PlayerStats[PlayerName].AllStats.Snowballs = 53
Just 2 examples of how I’d change the values.

Also thanks for the tip, I’ll make sure to change it.

The issue here could have something to do with nil values not printing properly on their own. A fix to this could be add something else into the print:

print(nil) -->> creates an empty new line

print(nil,"aaaaaa") -->> creates a new line with 'nil aaaaaa'

In this context that would mean key is nil.

Tried this, didn’t work :man_shrugging:

Does the second one have an index being created? Can we see the code that does?

This?
image

The metatable is set to PlayerData[PlayerName], not PlayerData[PlayerName].AllStats. Test is not a index of the former, so it won’t fire __newindex when it’s created.

Thing is… it’s basically identical to the other script, but it doesn’t work…

Why?

The one that does work, worked just fine, perfectly.

So both scripts are being tested on that code you replied to me with? (exactly that same code)

Yep. Even if they weren’t, I’d be changing the values in the same exact way.

Also this probably won’t help, but it worked earlier today. It stopped working on itself randomly. I undone my edits to the code but even the earlier versions that supposedly worked, didn’t work anymore.

Weird, I can’t figure it out rn sorry

Personally, if there is some error with it, I’d swear it’d be to do with setmetatable and where the new index is being made.

Maybe try using [] instead of . to make the new index? lol

The weirdest thing is that one works & the other doesn’t, when they’re both the exact same :boom:

Guess I’ll have to use a whole other way to set up my data handler. Probably

1 Like

@The_PieDude Figured it out. I was supposed to change the values by doing;
PlrStats[PlayerName].Snowballs = someValue
Because they’re linked & __index says the data in the whole table is the data in the allstats table.

1 Like