Yuan.Value = datast1:GetAsync(plr.UserId) or 0 --Right here what does this mean and what happens if it is 0 or not 0 datast1:SetAsync(plr.UserId, Yuan.Value)
Before I explain what it means in that specific case, you must first know what truthy values and falsey values are. It is a simple matter, so I will not write long of an explanation.
In Lua, truthy values are anything that is not false or nil. Numbers, strings and tables are examples of truthy values.
Falsey values, in Lua, are just false or nil.
x and y
will evaluate to x
if x
is falsey, y
otherwise.x or y
will evaluate to x
if x
is truthy, y
otherwise.not x
will evaluate to true
if x
is falsey, false
otherwise.When there is no saved data in a data store, :GetAsync()
returns nil. So that line would be the equivalent of Yuan.Value = nil or 0
if no data was found. This would evaluate to 0
if there was no data, since nil is falsey, and 0
is truthy (fun fact, in most languages 0
is falsey). However with IntValues and NumberValues, assigning the Value
property to nil will assign it to 0
so you would not even need the or 0
bit.