Does this Data Store do any things right?

local Players = game:GetService("Players")
local DataStoreService = game:GetService("DataStoreService")
local datastore = DataStoreService:GetDataStore("Test11")
local aurachange = game:GetService("ReplicatedStorage").Events.AuraChange
local RunService = game:GetService("RunService")

Players.PlayerAdded:Connect(function(plr)
	plr.CharacterAdded:Connect(function(character)
		local leaderstats = Instance.new("Folder", plr)
		leaderstats.Name = "leaderstats"
		local etc = Instance.new("Folder", leaderstats)
		etc.Name = "Etc"
		local auravalue = Instance.new("NumberValue")
		auravalue.Parent = etc
		auravalue.Name = "CurrentAura"
		auravalue.Value = 1
		local money = Instance.new("NumberValue")
		money.Parent = etc
		money.Name = "Money"
		money.Value = 100
		local reqmoney = Instance.new("NumberValue")
		reqmoney.Parent = etc
		reqmoney.Name = "RequimentMoney"
		reqmoney.Value = 300
		local Rolls = Instance.new("IntValue", leaderstats)
		Rolls.Name = "Rolls"
		local folder = Instance.new("Folder", leaderstats)
		folder.Name = "StorageOfAuras"
		for i, stor in pairs(plr.PlayerGui:WaitForChild("Main").invertory.AurasList:GetChildren()) do
			local number = tonumber(stor.Name)
			if number then
				local valuestor = Instance.new("StringValue")
				valuestor.Name = number
				valuestor.Parent = folder
				valuestor.Value = plr.PlayerGui:WaitForChild("Main").invertory.AurasList[number].SlotName.Text
			end
		end

		local Success, Data = pcall(function()
			return datastore:GetAsync(plr.UserId.."Table")
		end)

		local number = 0
		local guiplayer = plr.Character:WaitForChild("Head"):WaitForChild("GUIPlayers")

		if Data ~= nil then
			local function getem()
				for i, b in pairs(plr.leaderstats.StorageOfAuras:GetChildren()) do
					if tonumber(Data[tonumber(b.Name)][1]) then
						b.Value = Data[tonumber(b.Name)][2]
						plr.PlayerGui.Main.invertory.AurasList[tonumber(b.Name)].SlotName.Text = b.Value
						number = b.Name
						plr.PlayerGui.Main.invertory.AnimScript.Disabled = true
						wait(0.05)
						plr.PlayerGui.Main.invertory.AnimScript.Disabled = false
					else
						b:Destroy()	
					end
				end
			end

			getem()

			task.wait(1)
			if Data[number+1][1] ~= "Rolls" then
				repeat 
					local valuestor = Instance.new("StringValue")
					valuestor.Name = number + 1
					valuestor.Parent = folder
					local new = plr.PlayerGui.Main.invertory.AurasList[1]:Clone()
					new.Parent = plr.PlayerGui.Main.invertory.AurasList
					new.Name = number + 1
					getem()
					number += 1
					task.wait(0.1)
				until Data[number+1][1] == "Rolls"
			end
			Rolls.Value = Data[number+1][2]
			auravalue.Value = Data[number+2][2]
			money.Value = Data[number+3][2]
			reqmoney.Value = Data[number+4][2]
			plr.PlayerGui.Main.CoinsAndBiome.Coins.Text = money.Value.."$"
			plr.PlayerGui.Main.invertory.Buy.Text = "Buy ["..money.Value.."$]"
			if plr.leaderstats.StorageOfAuras[auravalue.Value].Value ~= "None" then
				guiplayer.Aura.Text = plr.leaderstats.StorageOfAuras[auravalue.Value].Value
				aurachange:Fire(plr)
			end
		else
			Rolls.Value = 0
			auravalue.Value = 1
		end
	end)
end)


Players.PlayerRemoving:Connect(function(Player) 
	local table1 = {}

	for i, stor in pairs(Player.leaderstats.StorageOfAuras:GetChildren()) do
		table.insert(table1,{ stor.Name, stor.Value})
	end

	table.insert(table1, {"Rolls", Player.leaderstats.Rolls.Value})
	table.insert(table1, {"AuraValue", Player.leaderstats.Etc.CurrentAura.Value})
	table.insert(table1, {"Money", Player.leaderstats.Etc.Money.Value})
	table.insert(table1, {"RequimentMoney", Player.leaderstats.Etc.RequimentMoney.Value})

	local Success, Error = pcall(function()
		print(table1)
		datastore:SetAsync(Player.UserId.."Table", table1)
	end)

	if Error == true then
		warn(Error)
	end
end)

This code saving…:

  • Inverotry
  • Coins
  • Reequipment Coins to buy Slots
  • Rolls Amout

It’s too long for nothing! organize your code, you’ll get there don’t worry, do functions and array

Use profileservice, this is way too much of a headache.

3 Likes

Just ignore him, some scripters are pretty toxic. But yeah try using profileservice this looks way too hard for you. Basic Usage - ProfileService

I’m aldery!

local ProfileTemplate = {
	Rolls = 0,
	Coins = 100,
	RequimentCoins = 300,
	CurrentAura = 1,
	Auras = {Slot1 = "None", Slot2 = "None", Slot3 = "None"},
	Settings = {AutoSkip = 0, AutoEquip = 0},
}

local ProfileService = require(game.ServerScriptService.Module.ProfileService)
local Players = game:GetService("Players")
local event = game:GetService("ReplicatedStorage").Events.AuraAndDice.AuraChange
local ProfileStore = ProfileService.GetProfileStore("PlayerData899", ProfileTemplate)
local Profiles = {}

local allowedPlayers = {
	["metrorunn"] = true,
	["megaomeg"] = true,
	["milch2659"] = true,
	["adws3233"] = true,
	["Koniderpony"] = true,
	["Maximplay47"] = true, 
	["Szymek123k"] = true,
	["Bencusss"] = true,
	["OneMakku"] = true,
	["sander_panter"] = true,
}

local function Leaderstats(player, profile)
	local leaderstats = Instance.new("Folder", player)
	leaderstats.Name = "leaderstats"
	local rolls = Instance.new("NumberValue", leaderstats)
	rolls.Name = "Rolls"
	if profile.Data.Rolls then
		rolls.Value = profile.Data.Rolls
	else
		rolls.Value = 0
	end
	local etc = Instance.new("Folder", leaderstats)
	etc.Name = "Etc"
	local storage = Instance.new("Folder", leaderstats)
	storage.Name = "Storage"
	local idsettings = Instance.new("Folder", leaderstats)
	idsettings.Name = player.UserId
	local coins = Instance.new("NumberValue", etc)
	coins.Name = "Coins"
	coins.Value = profile.Data.Coins
	local aura = Instance.new("NumberValue", etc)
	aura.Name = "CurrentAura"
	aura.Value = profile.Data.CurrentAura
	local aura = Instance.new("NumberValue", etc)
	aura.Name = "CurrentAura"
	aura.Value = profile.Data.CurrentAura
	local autoskip = Instance.new("NumberValue", idsettings)
	autoskip.Name = "AutoSkip"
	autoskip.Value = profile.Data.Settings[autoskip.Name]
	local autoequip = Instance.new("NumberValue", idsettings)
	autoequip.Name = "AutoEquip"
	autoequip.Value = profile.Data.Settings[autoequip.Name]
	player.Character:SetAttribute("AutoEquip", autoequip.Value)
	player.Character:SetAttribute("AutoSkip", autoskip.Value)
	player.PlayerGui:WaitForChild("Main").Settings.AutoEquip.EquipBox.Text = autoequip.Value
	player.PlayerGui:WaitForChild("Main").Settings.AutoSkip.SkipBox.Text = autoskip.Value
	local atribute = player.Character:SetAttribute("CurrentAura", profile.Data.CurrentAura)
	local reqcoins = Instance.new("NumberValue", etc)
	reqcoins.Name = "RequimentCoins"
	reqcoins.Value = profile.Data.RequimentCoins
	player.PlayerGui:WaitForChild("Main").CoinsAndBiome.Coins.Text = coins.Value.."$"
	player.PlayerGui:WaitForChild("Main").invertory.Buy.Text = "Buy ".."["..reqcoins.Value.."$]"
	
	local sortedSlots = {}
	for slotName, _ in pairs(profile.Data.Auras) do
		table.insert(sortedSlots, slotName)
	end
	table.sort(sortedSlots)  -- Sort slot names numerically

	for _, slotName in ipairs(sortedSlots) do
		local auraName = profile.Data.Auras[slotName]
		local slot = Instance.new("StringValue", storage)
		local currentAura = aura.Value
		slot.Name = slotName
		slot.Value = auraName
		local slotUI = script.Parent.Parent.Invertory.Slot1:Clone()
		slotUI.Name = slotName
		slotUI.Parent = player.PlayerGui:WaitForChild("Main").invertory.AurasList
		slotUI.SlotName.Text = auraName
		player.PlayerGui:WaitForChild("Main").invertory.AnimScript.Enabled = false
		task.delay(0.3, function()
			player.PlayerGui:WaitForChild("Main").invertory.AnimScript.Enabled = true
		end)
		if slot.Name == "Slot"..currentAura then
			local guiplayer = player.Character.Head:WaitForChild("GUIPlayers").Aura
			guiplayer.Text = auraName
			event:Fire(player)
		end
		local number = tonumber(slot.Name:match("%d+"))
		if currentAura == number then
			slotUI.EquipButton.Text = "Equipped"
		end
	end
end

local function PlayerAdded(player)
	if not allowedPlayers[player.Name] then
		player:Kick("You aren't a tester. Discord: https://discord.com/invite/PfvU64x86y")
	end
	local profile = ProfileStore:LoadProfileAsync("Player_" .. player.UserId)
	if profile ~= nil then
		profile:AddUserId(player.UserId)
		profile:Reconcile()
		profile:ListenToRelease(function()
			Profiles[player] = nil
			player:Kick()
		end)
		if player:IsDescendantOf(Players) == true then
			Profiles[player] = profile
			Leaderstats(player, profile)
		else
			profile:Release()
		end
	else
		player:Kick() 
	end
end

for _, player in ipairs(Players:GetPlayers()) do
	task.spawn(PlayerAdded, player)
end

Players.PlayerAdded:Connect(PlayerAdded)

Players.PlayerRemoving:Connect(function(player)
	local profile = Profiles[player]
	if profile ~= nil then
		profile.Data.CurrentAura = player.leaderstats.Etc.CurrentAura.Value
		profile:Release()
		profile.Data.Rolls = player.leaderstats.Rolls.Value
		profile.Data.Coins = player.leaderstats.Etc.Coins.Value
		profile.Data.RequimentCoins = player.leaderstats.Etc.RequimentCoins.Value
		local stor = player.leaderstats.Storage
		profile.Data.Settings["AutoSkip"] = player.leaderstats[player.UserId].AutoSkip.Value
		profile.Data.Settings["AutoEquip"] = player.leaderstats[player.UserId].AutoEquip.Value
		for i, v in pairs(stor:GetChildren()) do
			print(profile.Data.Auras[v.Name])
			profile.Data.Auras[v.Name] = v.Value
		end
		
		for i, x in pairs(profile.Data.Auras) do
			local object = stor:FindFirstChild(i)
			if object == nil then
				profile.Data.Auras[i] = nil
			end
		end
	end
end)

Yes, but Suphis dataStore it better !

I’ve heard good things about it, but I just stick with profileservice. Suphi is a good scripter but atleast I don’t do this:

-- Me when scripting
if cheese == 1 then
print(cheese) -- ok
end
-- Suphi when scripting
if cheese == 1 then print(cheese) end -- not ok

Yes its true x), but he make this for more readable for users

I never understood putting if statements in one line, it just looks really weird.