Besides nitpicks, there are two things you are doing “incorrectly”.
-
Don’t use the second argument of Instance.new if you’re modifying other properties. When an instance hasn’t been attached to the DataModel yet you’re just modifying pieces of data. Once it gets parented, the instance falls into a bunch of different pipelines including listening for changes to the object. Always set up your instances first, then parent them. More information.
-
You’re probably not going to want to call SetAsync every time a player dies. That’s a quick way to run out of DataStore request budget and that’s not including the throttle that occurs when attempting to write to the same key within 6 seconds.
Aim to only save when the player isn’t connected to the session anymore. The two most common points to execute a full save are via PlayerRemoving and BindToClose.