Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

what does 'or 0' mean in datastores and what happens if it is 0?

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) 

4 comments

0

or 0 means if the user has no data. This is the data you're giving the player in other words.

0

so it's saying if the player has no data, set it to this value (0)

0

so if you wanted people to have 100 Yuan when they are new to the game, set it to or 100

0

This is not how you should be using a data store.

1 answer

✓ Accepted answer

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.

This discussion is preserved as it was. New answers, comments, and votes are closed.