Are there bad practices in my script?

Belief in infallibility is what bugs are made of!

1 Like

No argument here, being overconfident in something you shouldn’t be is a huge source of bugs. But considering we’re talking about a single function here, and it’s documented to never return nil and known to raise an error whenever the instance can’t be created, and considering your argument about “local allocations” is completely invalid because that’s not how replication works (the server never depends on an allocation being made on any one client), it’s pretty fair to believe in this very specific case, this specific function will never return nil.

Claiming that it can, just because it’s dAaAAangerous to AsSUuUUUmE when it’s clearly documented as never returning nil at all (notice the lack of ?), is a big source of cargo cult programming which I personally despise.

1 Like

It isn’t recommended by Roblox Staff to use the parent argument for Instance.new.

That’s about all I can see (I don’t use DataStore2, so I can’t confirm if your code is well-protected against data loss).


If your code is already functional, I recommend re-directing this to #help-and-feedback:code-review instead of this category

2 Likes

Documentation means naught, only under an infinite testing environment can the pure return value ever be truly defined. Saying “It hasn’t crashed yet” is not enough.

1 Like

I never knew that category exists. But thank you. I will consider that next time when I want feedback.

Or disassembling the Roblox binaries and seeing that there isn’t even a code path in Instance.new capable of returning nil.

Seriously, go grab IDA64, load up the Roblox engine, and see that Instance.new doesn’t have a single code path that can push nil onto the Luau stack. Or if you can’t do that, go ahead and test it yourself in Studio. Create instances in an infinite loop. Eventually it will error, and Studio might even crash, but it will not return nil.

1 Like

That last byte of allocation, or operation, is the one to shoot your whole leg off! It might not be Roblox’s superb system, the operating system has many cores, thousands of threads, all competing for operation time and execution windows.

1 Like

Dude, literally in like the history of development I have never seen anybody say that Instance.new() return nil, and same for me.

This argument is getting off topic, could you please try to help the OP with their issue instead.

3 Likes

Over and out, I have nothing left to say anyway.

1 Like

Anyways the only suggestion I have is not stacking two things together like this:

	local CurrencyData = Datastore2Module("Currency", plr):GetTable(DefUserData.Currency)

Edit: I don’t know how this will affect any type of performance.

1 Like

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