DataStore Scheme

Hello! I’ve spotted a few discouraged practices that you might want to fix:

  1. Using the second parameter of Instance.new(), setting the parent before the properties:
local leaderstats = Instance.new(“Folder”, player)
leaderstats.Name = “leaderstats”

local Cash = Instance.new(“IntValue”, leaderstats)
Cash.Name = “Cash”

It’s far more expensive to modify an already replicated object than setting its properties before setting its parent. When creating a new object, it’s best to do everything while it’s still just memory. I recommend you go check out these reads:

For your current code, I’d change it to this:

local leaderstats = Instance.new(“Folder”)
leaderstats.Name = “leaderstats”
local Cash = Instance.new(“IntValue”, leaderstats)
Cash.Name = “Cash”
leaderstats.Parent = player
  1. Use UpdateAsync() instead of SetAsync():

From this great PSA by ForeverHD: SetAsync completely overwrites data. This can be an issue if the save messes up, and you have no way to verify and do checks with data. UpdateAsync respects the previous entry and gives you the ability to define a callback:

Hope this helps! :slight_smile:

3 Likes