As a Roblox developer, it is currently too hard to assign a default value to a variable only when it’s nil without writing it out the long way every time.
Right now if I want to set a value only when something is nil, I have to write:
config.Volume = config.Volume == nil and 1 or config.Volume
or
if config.Volume == nil then
config.Volume = 1
end
This comes up constantly when working with config tables, player data, optional function arguments, and caching patterns where I only want to compute or assign something if it hasn’t already been set. Other modern languages handle this with a nullish coalescing assignment operator (??=), which only assigns when the left side is nil. Luau has no equivalent, so I end up writing repetitive boilerplate or relying on the and/or trick, which is error prone with falsy-but-not-nil values like false.
The and/or pattern silently overwrites a legitimate false value because it checks for truthiness rather than nil. That means boolean config flags and similar patterns can’t safely use it at all.
If Roblox is able to address this issue, it would improve my development experience because I could write something like:
config.Volume ??= 1
instead of the longer patterns above. This would cut down on repeated boilerplate, make intent clearer (only assign if nil), and avoid the and/or bug where a legitimate false gets overwritten. The operator would be consistent with Luau’s existing compound assignment operators (+=, -=, etc.) and would not require any new semantics beyond nil-checking on assignment.
They were asking OP to elaborate on their claim that an operator which was not documented supposedly exists in Luau. Surely reading comprehension isn’t that hard?
That’s exactly how I interpreted the comment too… That’s why I pointed out it was the Feature Requests category? And you’re the one telling me reading comprehension isn’t hard…
I hope you realize that, this category being for requests, users need to support them. And users need primarily to know what they’re supporting. This operator isn’t documented in the Creator Docs, so a question “what is it?” fits perfectly for future readers.
This is getting off-topic and I still haven’t gotten an answer so, I’d appreciate at this point just continuing to use the like button.
Because prior to OP editing it out of his post, he was implying that the operator ?? (NOT ??=) actually existed in either standard Lua or Luau and that is what was being asked about.
alr bro sorry, basically this category is for requests and the ?? operator doesn’t exist, that’s what I meant when I said it’s the feature requests category, cause the operator is requested and doesn’t exist yet