function dataManager:GetData(player)
local myData = playerDataStore:GetAsync(player.UserId) or {}
myData.level = myData.level or 1
myData.exp = myData.exp or 0
myData.gold = myData.gold or 100
myData.gems = myData.gems or 0
myData.class = myData.class or 'Knight'
local playerFolder = Instance.new('Folder')
playerFolder.Name = 'PlayerFolder'
local level = Instance.new('IntValue')
level.Name = 'Level'
level.Value = myData.level
level.Parent = playerFolder
local exp = Instance.new('IntValue')
exp.Name = 'Exp'
exp.Value = myData.exp
exp.Parent = playerFolder
local gold = Instance.new('IntValue')
gold.Name = 'Gold'
gold.Value = myData.gold
gold.Parent = playerFolder
local gems = Instance.new('IntValue')
gems.Name = 'Gems'
gems.Value = myData.gems
gems.Parent = playerFolder
local class = Instance.new('StringValue')
class.Name = 'Class'
class.Value = myData.class
class.Parent = playerFolder
playerFolder.Parent = player
playerData[player.UserId] = myData
end
This is kinda how I’ve always set up my data for games, creating a data store for them, then created values inside the player (so UI can easily access their stats to display their level, cash, etc.)
Few things I’m not certain on. If this is the most efficient way to go about this. I have thought about just firing an event whenever one of the values is update, and have the UI look for, and just change whatever needs to be changed from there. Just keeping the data stores and removing the values seems like it would be safer too, as I know players can just edit values from within their player, and that is why all the values are set to the myData (the data store) values, as there is no way a player can edit these.
Any words of advice?? If it would be better to just fire and event off whenever the data store is changed???