Could I get feedback on a data store?

So I’ve been working on a data store for some time now, and I think I’ve almost perfected it. Can I get feedback on what I should add, remove or change?

A little directory
leaderstats Will only bring up the level of the user
leaderstats2 will not bring up the stats, as it should appears on a custom leaderstats menu

while script.Parent.Parent ~= workspace do wait() end

local DataStoreService = game:GetService("DataStoreService")

local myDataStore = DataStoreService:GetDataStore("aKDFKSLIEJ345OIDS(StoreA)DE")

game.Players.PlayerAdded:Connect(function(player)

	local leaderstats = Instance.new("Folder")
	leaderstats.Name = "leaderstats"
	leaderstats.Parent = player

	local leaderstats2 = Instance.new("Folder")
	leaderstats2.Name = "leaderstats2"
	leaderstats2.Parent = player


	local Money = Instance.new("IntValue")
	Money.Name = "Money"
	Money.Value = 0
	Money.Parent = leaderstats2

	local LevelPoint = Instance.new("IntValue")
	LevelPoint.Name = "LevelPoint"
	LevelPoint.Value = 0
	LevelPoint.Parent = leaderstats2

	local Level = Instance.new("StringValue")
	Level.Name = "Level"
	Level.Value = "Basic"
	Level.Parent = leaderstats

	local Gold = Instance.new("IntValue")
	Gold.Name = "Gold"
	Gold.Value = 0
	Gold.Parent = leaderstats2
	
	local Snowflakes = Instance.new("IntValue")
	Snowflakes.Name = "Snowflakes"
	Snowflakes.Value = 0
	Snowflakes.Parent = leaderstats2

	local ParkPoints = Instance.new("IntValue")
	ParkPoints.Name = "ParkPoints"
	ParkPoints.Value = 0
	ParkPoints.Parent = leaderstats2

	local Silver = Instance.new("IntValue")
	Silver.Name = "Silver"
	Silver.Value = 0
	Silver.Parent = leaderstats2


local data
local data2
local data3
local data4
local data5
local data6
local success, errormessage = pcall(function()
	data = myDataStore:GetAsync(player.UserId.."-Money")
	data2 = myDataStore:GetAsync(player.UserId.."-Gold")
	data3 = myDataStore:GetAsync(player.UserId.."-Snowflakes")
	data4 = myDataStore:GetAsync(player.UserId.."-ParkPoints")
	data5 = myDataStore:GetAsync(player.UserId.."-Silver")
	data6 = myDataStore:GetAsync(player.UserId.."-LevelPoint")
end)

if success then 
	Money.Value = data
	Gold.Value = data2
	Snowflakes.Value = data3
	Silver.Value = data5
	ParkPoints.Value = data4
	LevelPoint.Value = data6
else
	print("There was an error whilst getting your data!")
	warn(errormessage)
end
end)
	game.Players.PlayerRemoving:Connect(function(player)
		local success, errormessage = pcall(function()
			myDataStore:SetAsync(player.UserId.."-Money",player.leaderstats2.Money.Value)
			myDataStore:SetAsync(player.UserId.."-Gold",player.leaderstats2.Gold.Value)
			myDataStore:SetAsync(player.UserId.."-Snowflakes",player.leaderstats2.Snowflakes.Value)
			myDataStore:SetAsync(player.UserId.."-Park Points",player.leaderstats2.ParkPoints.Value)
			myDataStore:SetAsync(player.UserId.."-Silver",player.leaderstats2.Silver.Value)
			myDataStore:SetAsync(player.UserId.."-Level",player.leaderstats2.LevelPoint.Value)
			
		end) 
	if success then
		print("Player Data Successfully saved!")
	else
		print("There was an error saving your data!")
		warn(errormessage)	
	end
	end)




amount = 10 
timedelay = 120 
currencyname = "Money"
game.Players.PlayerAdded:Connect(function(plr)
while true do
	wait(timedelay)
	for i,v in pairs(game.Players:GetPlayers()) do
		if v:FindFirstChild("leaderstats2") and v then
			v[currencyname].Value = v.leaderstats2[currencyname].Value + amount
		if plr:GetRankInGroup(4585254) >= 127 or game:GetService("GamePassService"):PlayerHasPass(plr, 9536293) then
			v.leaderstats2[currencyname].Value = v.leaderstats2[currencyname].Value + amount*2
		end
		end
	end
end
end)


--[[
Learner
Beginner
Indepdent Skier
Intermediate Beginner
Intermediate
Independent Intermediate
Advanced Beginner
Advanced Skier
Offtrail Expert
--]]

game.Players.PlayerAdded:Connect(function(plr)
while true do
	wait(.1)
	for i,v in pairs(game.Players:GetPlayers()) do
	if v:FindFirstChild("leaderstats") and v then
	if plr:GetRankInGroup(4585254) == 127 then
		v.leaderstats.level.Value = "Developer"
	if plr:GetRankInGroup(4585254) == 255 then
		v.leaderstats.level.Value = "Founder"
	if v.leaderstats2.LevelPoint.Value >= 10000000 then
		v.leaderstats.level.Value = "Offtrail Expert"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 10000000
elseif v.leaderstats2.LevelPoint.Value >= 1000000 then
		v.leaderstats.level.Value = "Advanced Skier"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 1000000
elseif v.leaderstats2.LevelPoint.Value >= 500000 then
		v.leaderstats.level.Value = "Advanced Beginner"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 500000
elseif v.leaderstats2.LevelPoint.Value >= 100000 then
		v.leaderstats.level.Value = "Independent Intermediate"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 100000
elseif v.leaderstats2.LevelPoint.Value >= 50000 then
		v.leaderstats.level.Value = "Intermediate"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 50000
elseif v.leaderstats2.LevelPoint.Value >= 40000 then
		v.leaderstats.level.Value = "Intermediate Beginner"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 40000
elseif v.leaderstats2.LevelPoint.Value >= 30000 then
		v.leaderstats.level.Value = "Indepdent Skier"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 30000
elseif v.leaderstats2.LevelPoint.Value >= 20000 then
		v.leaderstats.level.Value = "Beginner"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 20000
elseif v.leaderstats2.LevelPoint.Value >= 10000 then
		v.leaderstats.level.Value = "Learner"
		v.leaderstats2.Money.Value = v.leaderstats2.Money.Value - 10000
end
		end
	end
end
end
end
end)
3 Likes

I would recommend using a table to save more than one value and don’t use :SetAsync() use :UpdateAsync() it is more reliable.

3 Likes

hmmm its great, but if i was you i would use dictionaries to save
{

["Coins"] = 46346343845568464564834545;
["Gold"] = 489498498;
["Level"] = 19195159818;

}
2 Likes

Do you think I should have dictionaries, but then create a require module to the datastore 2
Datastore 2

your choice, i just gave a recommendation

1 Like

Wouldn’t it be better to use continue on the if statements instead? :thinking:

On the "ranks" function at the end
To keep it organized somewhat it like this

Just my recommendation.

2 Likes

That is a good idea, thanks for the feedback.

1 Like