How to switch from set async to update async without loosing data?

I’ve explained the details, but i need this beacuse my players are expereincing full data whipes

SetAsync works just like UpdateAsync. So instead of doing:

:SetAsync("Player", {"hello"});

--You do:

:UpdateAsync("Player", function(key, oldValue)
    return {"hello"}; --The value you return is the value that will be set
end);

What about the function with the old value and stuff like that?

If you need to implement it then do so, but it is not necessary.

key: The key being saved. So “Player” in this example

oldValue: It was the previous value, this is useful when adding for example. You can have a reward system that adds 500 coins and to do that you get the old value (the previous coins) and add 500.

:UpdateAsync("Player", function(key, oldValue)
    return oldValue + 500;
end);
1 Like

Oh damn, i always thought i had to do that function that i never figured out.

So if i’m not mistaken this will make it so whenever a player looses data it doesn’t get wiped it only returns to the previous data?

Old Value is the current value you could say so. When you return the new data then it gets set. If your data is empty then Old Value will be empty.

UpdateAsync does ensure that the data is set, if an error happens it will keep trying to set the data until it succeeds. However, if your game wipes data then it is probably related to how you save data. There must be something causing it to wipe data.

Let’s say this is my data structure:

  • Database
    • Players (List)
      • Player1

You are probably the one causing the data wipes wihout realising it. In this example we have a list called Players and the only player registered called Player1. Maybe what is happening is that you are doing something like this:

:SetAsync("Players", {newPlayer={}});

This is bad code since I am wiping all the table of players when a new player joins (Note: The bad thing here isn’t SetAsync, SetAsync works fine. The problem is how you are setting the data). An example with update async would be:

:UpdateAsync("Players", function(key, players)
    players["newPlayer"] = {};
    return players;
end);

Another example, lets say I am updating a player’s coins.

:SetAsync("Player1", {
    Coins = 30;
});

This is bad code since I am wiping the entire player to update the coins, this is the same syntax in update async.

:UpdateAsync("Player1", function(key, player)
    player.Coins = 30;
--  See how the player wasen't wiped? I am only modifying key "Coins" and not the entire player.
    return player;
end);

Lemme show you the script, cuss it would probably be easier for you to understand:

local function TableValues(Player)
	local Player_stats = {}

	for i, v in pairs(Player.ValuesFolder:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.Settings:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.Codes:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.DnaOwned:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.EquippedFolder:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.RanksOwned:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.ToolsOwned:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	return Player_stats
end
game.Players.PlayerRemoving:Connect(function(Player)
	local Name = Player.Name
	if Player.ValuesFolder.LoadingData.Value == false then
		local Key = Player.UserId
		local Table = TableValues(game.ServerStorage[Name])
		if Table ~= TableValues(game.ServerStorage.DefaultData) then
			print()
			local S, E = pcall(function()
				for i, v in pairs(game.Players:GetChildren()) do
					local Table = TableValues(v)
					local S, E = pcall(function()
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						else
							repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end)
					if S then
						print("DataStored")
					else
						warn(E.." attempting retry...")
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							task.wait(6)
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end
				end
			end)
	--		game.ServerStorage[Name]:Destroy()
			if S then
				print("DataStored")
			else
				warn(E)
			end
		end
	else
		print("Data Wasn't Loaded")
	end
end)

That was the save, lemme show you the get async

local data
	local success, errorMessage = pcall(function()
		if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0 then
			data = PlayerData:GetAsync(Player.UserId)
		else 
			repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0
			data = PlayerData:GetAsync(Player.UserId)
		end
	end)

	for i, v in pairs(Player.PlayerGui:WaitForChild("GameShop").MainFrame.Dna1.ToolList:GetChildren()) do
		local dna = Instance.new("BoolValue", DnaOwned)
		dna.Name = v.Name
		if dna.Name == "Kid" then
			dna.Value = true
		end
		print("SuccessDna")
	end

	if data ~= nil and success then
		local s, e = pcall(function()
			if data["TestSize"] == nil then
				if data["Size"] ~= nil then
					TestSize.Value = tostring(data["Size"])
					print("Nil")
				end
			else
				TestSize.Value = data["TestSize"]
				print("NotNil")
			end
			if data["RealCoins"] == nil then
				if data["Coins"] ~= nil then
					RealCoins.Value = tostring(data["Coins"])
					print("Nil")
				end
			else
				RealCoins.Value = data["RealCoins"]
				print("NotNil")
			end


			TotalSize.Value = data["TotalSize"]
			if tonumber(RealCoins.Value) / 1000 >= 1 then
				Coins.Value = Format(tonumber(RealCoins.Value), 1)
			else
				Coins.Value = tonumber(RealCoins.Value)
			end

			Kills.Value = data["Kills"]
			MaxHealth.Value = data["MaxHealth"]
			SizeVal2.Value = data["SizeVal2"]
			CoinsVal2.Value = data["CoinsVal2"]
			Music.Value = data["Music"]
			SFX.Value = data["SFX"]
			Popups.Value = data["Popups"]
			Sell.Value = data["Sell"]
			Teleport.Value = data["Teleport"]
			MaxSizeDesc.Value = data["MaxSizeDesc"]
			Likes.Value = data["1.5mvisits"]
			Visits.Value = data["5klikes"]
			YoutuberCode.Value = data["doctorplanezonyt"]
			updatedelay.Value = data["updatedelay"]
			sorryfordataloss.Value = data["sorryfordataloss"]
			DNA.Value = data["DNA"]
			Tool.Value = data["Tool"]
			Rank.Value = data["Rank"]
			SecLeftOf10XSize.Value = data["SecLeftOf10XSize"]
			SecLeftOf30XSize.Value = data["SecLeftOf30XSize"]
			SecLeftOfAutoSell.Value = data["SecLeftOfAutoSell"]
			Stage2.Value = data["Stage 2"]
			Stage3.Value = data["Stage 3"]
			Stage4.Value = data["Stage 4"]
			Stage5.Value = data["Stage 5"]
			Stage6.Value = data["Stage 6"]
			Stage7.Value = data["Stage 7"]
			Stage8.Value = data["Stage 8"]
			Stage9.Value = data["Stage 9"]
			Stage10.Value = data["Stage 10"]
			Stage11.Value = data["Stage 11"]
			Stage12.Value = data["Stage 12"]
			Stage13.Value = data["Stage 13"]
			Stage14.Value = data["Stage 14"]
			Stage15.Value = data["Stage 15"]
			Stage16.Value = data["Stage 16"]
			Stage17.Value = data["Stage 17"]
			Stage18.Value = data["Stage 18"]
			Stage19.Value = data["Stage 19"]
			Stage20.Value = data["Stage 20"]
			RobuxSpent.Value = data["RobuxSpent"]
			RebirthMultiplier.Value = data["RebirthMultiplier"]
			WalkSpeed.Value = data["WalkSpeed"]
			Concealed.Value = data["Concealed"]
			for i, v in pairs(ToolsOwned:GetChildren()) do
				v.Value = data[v.Name]
			end

			for i, v in pairs(DnaOwned:GetChildren()) do
				v.Value = data[v.Name]
			end
			if data["Height"] > 0 then
				Height.Value = data["Height"]
				Width.Value = data["Width"]
				Head.Value = data["Head"]
				Depth.Value = data["Depth"]
			else
				Height.Value = 1
			end
		end)

		game.ReplicatedStorage.PlayerAdded:FireClient(Player, Coins.Value, Size.Value, Height.Value)
		Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Cash"):WaitForChild("CoinsText").Text = Coins.Value
		Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Strength"):WaitForChild("StrengthText").Text = Size.Value

		if Music.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Concealed.Value == true then
			Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Conceal").Image = "rbxassetid://9184613716"	
		end

		if SFX.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Popups.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Sell.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Teleport.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end
	elseif success == false and data ~= nil then
		LoadingData.Value = true
		Player.PlayerGui:WaitForChild("PopUps"):WaitForChild("ErrorGettingData").Visible = true
		while LoadingData.Value == true do
			for i = Retrysec.Value, 0, -1 do
				Player.PlayerGui.PopUps.ErrorGettingData.Text = "Data Error, Retrying in: "..i
				wait(1)
			end
			local success, errorMessage = pcall(function()
				if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0 then
					data = PlayerData:GetAsync(Player.UserId)
				else
					repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0
					data = PlayerData:GetAsync(Player.UserId)
				end
			end)
			if success == true then
				LoadingData.Value = false
				Player.PlayerGui.PopUps.ErrorGettingData.Text = "Data Recived"
				Player.PlayerGui.PopUps.ErrorGettingData.TextColor3 = Color3.fromRGB(85, 255, 0)
				local s, e = pcall(function()
					if data["TestSize"] == nil then
						if data["Size"] ~= nil then
							TestSize.Value = tostring(data["Size"])
							print("Nil")
						end
					else
						TestSize.Value = data["TestSize"]
						print("NotNil")
					end

					if data["RealCoins"] == nil then
						if data["Coins"] ~= nil then
							RealCoins.Value = tostring(data["Coins"])
							print("Nil")
						end
					else
						RealCoins.Value = data["RealCoins"]
						print("NotNil")
					end


					TotalSize.Value = data["TotalSize"]
					if tonumber(RealCoins.Value) / 1000 >= 1 then
						Coins.Value = Format(tonumber(RealCoins.Value), 1)
					else
						Coins.Value = tonumber(RealCoins.Value)
					end

					Kills.Value = data["Kills"]
					MaxHealth.Value = data["MaxHealth"]
					SizeVal2.Value = data["SizeVal2"]
					CoinsVal2.Value = data["CoinsVal2"]
					Music.Value = data["Music"]
					SFX.Value = data["SFX"]
					Popups.Value = data["Popups"]
					Sell.Value = data["Sell"]
					Teleport.Value = data["Teleport"]
					MaxSizeDesc.Value = data["MaxSizeDesc"]
					Likes.Value = data["1.5mvisits"]
					Visits.Value = data["5klikes"]
					YoutuberCode.Value = data["DoctorPlanezOnYT"]
					DNA.Value = data["DNA"]
					Tool.Value = data["Tool"]
					Rank.Value = data["Rank"]
					SecLeftOf10XSize.Value = data["SecLeftOf10XSize"]
					SecLeftOf30XSize.Value = data["SecLeftOf30XSize"]
					SecLeftOfAutoSell.Value = data["SecLeftOfAutoSell"]
					Stage2.Value = data["Stage 2"]
					Stage3.Value = data["Stage 3"]
					Stage4.Value = data["Stage 4"]
					Stage5.Value = data["Stage 5"]
					Stage6.Value = data["Stage 6"]
					Stage7.Value = data["Stage 7"]
					Stage8.Value = data["Stage 8"]
					Stage9.Value = data["Stage 9"]
					Stage10.Value = data["Stage 10"]
					Stage11.Value = data["Stage 11"]
					Stage12.Value = data["Stage 12"]
					Stage13.Value = data["Stage 13"]
					Stage14.Value = data["Stage 14"]
					Stage15.Value = data["Stage 15"]
					Stage16.Value = data["Stage 16"]
					Stage17.Value = data["Stage 17"]
					Stage18.Value = data["Stage 18"]
					Stage19.Value = data["Stage 19"]
					Stage20.Value = data["Stage 20"]
					RobuxSpent.Value = data["RobuxSpent"]
					RebirthMultiplier.Value = data["RebirthMultiplier"]
					WalkSpeed.Value = data["WalkSpeed"]
					Concealed.Value = data["Concealed"]
					for i, v in pairs(ToolsOwned:GetChildren()) do
						v.Value = data[v.Name]
					end

					for i, v in pairs(DnaOwned:GetChildren()) do
						v.Value = data[v.Name]
					end
					if data["Height"] > 0 then
						Height.Value = data["Height"]
						Width.Value = data["Width"]
						Head.Value = data["Head"]
						Depth.Value = data["Depth"]
					else
						Height.Value = 1
					end
				end)

				game.ReplicatedStorage.PlayerAdded:FireClient(Player, Coins.Value, Size.Value, Height.Value)
				Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Cash"):WaitForChild("CoinsText").Text = Coins.Value
				Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Strength"):WaitForChild("StrengthText").Text = Size.Value

				if Music.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Concealed.Value == true then
					Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Conceal").Image = "rbxassetid://9184613716"	
				end

				if SFX.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Popups.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Sell.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Teleport.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end
				Player.PlayerGui.PopUps.ErrorGettingData:TweenPosition(UDim2.new(0.637, 0,1.05, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
			else
				Retrysec.Value *= 2
			end
		end
	end

Can you send me the entire get async script, so i can see where the values are set and where they are placed?

1 Like

Their placed in serverstorage. Lemme show u the entire 1500 line code:/

local DataStoresService = game:GetService("DataStoreService")

local abbrev = {"","K", "M", "B", "T", "Qa", "Qi", "Sx", "Sp","Oc", "No", "Dc", "Ud", "Dd", "Td", "Qad", "Qid", "Sxd", "Spd", "Ocd", "Nod", "Vg", "Uvg"}

local function Format(value, idp)
	local ex = math.floor(math.log(math.max(1, math.abs(value)), 1000))
	local abbrevs = abbrev [1 + ex] or ("e+"..ex)
	local normal = math.floor(value * ((10 ^ idp) / (1000 ^ ex))) / (10 ^ idp)

	return ("%."..idp.."f%s"):format(normal, abbrevs)
end

local SizeLeaderboard = DataStoresService:GetOrderedDataStore("SizeLeaderbard")
local CoinsLeaderboard = DataStoresService:GetOrderedDataStore("CoinsLeaderbard")
local KillsLeaderboard = DataStoresService:GetOrderedDataStore("KillsLeaderboardR")
local RobuxSpentLeaderboard = DataStoresService:GetOrderedDataStore("RobuxSpentLeaderboardR")
local PlayerData = DataStoresService:GetDataStore("PlayersDa")
local MS = game:GetService("MarketplaceService")
local BS = game:GetService("BadgeService")
local TweenService = game:GetService("TweenService")
local RedButton = "rbxassetid://9211125198"
local GreenButton = "rbxassetid://9204425024"

local PhysicsService = game:GetService("PhysicsService")
local Players = game:GetService("Players")

local playerCollisionGroupName = "Players"
PhysicsService:CreateCollisionGroup(playerCollisionGroupName)
PhysicsService:CollisionGroupSetCollidable(playerCollisionGroupName, playerCollisionGroupName, false)

local RebirthValues = {
	["Stage 1"] = 1;
	["Stage 2"] = 2;
	["Stage 3"] = 5;
	["Stage 4"] = 19;
	["Stage 5"] = 99;
	["Stage 6"] = 499;
	["Stage 7"] = 2999;
	["Stage 8"] = 19000;
	["Stage 9"] = 159000;
	["Stage 10"] = 1900000;
	["Stage 11"] = 29900000;
	["Stage 12"] = 599000000;
	["Stage 13"] = 1490000000;
	["Stage 14"] = 44900000000;
	["Stage 15"] = 159000000000;
	["Stage 16"] = 629000000000000;
	["Stage 17"] = 28900000000000000;
	["Stage 18"] = 1400000000000000000;
	["Stage 19"] = 7790000000000000000;
	["Stage 20"] = 555000000000000000000;
}


local SpeedTable = {
	["Stage 1"] = 24;
	["Stage 2"] = 30;
	["Stage 3"] = 34;
	["Stage 4"] = 38;
	["Stage 5"] = 42;
	["Stage 6"] = 46;
	["Stage 7"] = 50;
	["Stage 8"] = 60;
	["Stage 9"] = 65;
	["Stage 10"] = 70;
	["Stage 11"] = 75;
	["Stage 12"] = 80;
	["Stage 13"] = 85;
	["Stage 14"] = 90;
	["Stage 15"] = 95;
	["Stage 16"] = 100;
	["Stage 17"] = 105;
	["Stage 18"] = 110;
	["Stage 19"] = 115;
	["Stage 20"] = 120;
}

local SpeedTableX2 = {
	["Stage 1"] = 24 * 2;
	["Stage 2"] = 30 * 2;
	["Stage 3"] = 34 * 2;
	["Stage 4"] = 38 * 2;
	["Stage 5"] = 42 * 2;
	["Stage 6"] = 46 * 2;
	["Stage 7"] = 50 * 2;
	["Stage 8"] = 60 * 2;
	["Stage 9"] = 65 * 2;
	["Stage 10"] = 70 * 2;
	["Stage 11"] = 75 * 2;
	["Stage 12"] = 80 * 2;
	["Stage 13"] = 85 * 2;
	["Stage 14"] = 90 * 2;
	["Stage 15"] = 95 * 2;
	["Stage 16"] = 100 * 2;
	["Stage 17"] = 105 * 2;
	["Stage 18"] = 110 * 2;
	["Stage 19"] = 115 * 2;
	["Stage 20"] = 120 * 2;
}


local previousCollisionGroups = {}

local function setCollisionGroup(object)
	if object:IsA("BasePart") then
		previousCollisionGroups[object] = object.CollisionGroupId
		PhysicsService:SetPartCollisionGroup(object, playerCollisionGroupName)
	end
end

local function setCollisionGroupRecursive(object)
	setCollisionGroup(object)

	for _, child in ipairs(object:GetChildren()) do
		setCollisionGroupRecursive(child)
	end
end

local function resetCollisionGroup(object)
	local previousCollisionGroupId = previousCollisionGroups[object]
	if not previousCollisionGroupId then return end 

	local previousCollisionGroupName = PhysicsService:GetCollisionGroupName(previousCollisionGroupId)
	if not previousCollisionGroupName then return end

	PhysicsService:SetPartCollisionGroup(object, previousCollisionGroupName)
	previousCollisionGroups[object] = nil
end

local Players = game:GetService("Players")
local SizeTweenInfo = TweenInfo.new(
	0.3,
	Enum.EasingStyle.Linear,
	Enum.EasingDirection.In,
	0,
	false,
	0
)

local GroupColors = {
	["Founder"] = Color3.fromRGB(85, 255, 0) ;
	["Moderator"] = Color3.fromRGB(255, 0, 0) ;
	["Tester"] = Color3.fromRGB(255, 85, 0) ;
	["Influencers"] = Color3.fromRGB( 85, 85, 255);
	["Fans"] = Color3.fromRGB( 85, 170, 255);
}

game.Players.PlayerAdded:Connect(function(Player)
	local PetImageTables = {
		["Dog"] = "rbxassetid://9412120794";
		["Cat"] = "rbxassetid://9412318804";
		["Bear"] = "rbxassetid://9412430355";
		["Bunny"] = "rbxassetid://9412407829";
		["Fox"] = "rbxassetid://9413125685";
		["Deer"] = "rbxassetid://9413151161";
	}

	local leaderstats = Instance.new("Folder", Player)
	leaderstats.Name = "leaderstats"

	local HiddenTools = Instance.new("Folder", Player)
	HiddenTools.Name = "HiddenTools"

	local Size = Instance.new("StringValue", leaderstats)
	Size.Name = "Size"

	local Coins = Instance.new("StringValue", leaderstats)
	Coins.Name = "Coins"

	local Stage = Instance.new("StringValue", leaderstats)
	Stage.Name = "Stage"
	Stage.Value = "Stage 1"

	local EquippedFolder = Instance.new("Folder", Player)
	EquippedFolder.Name = "EquippedFolder"

	local DataWithNoSave = Instance.new("Folder", Player)
	DataWithNoSave.Name = "DataWithNoSave"

	local DNA = Instance.new("StringValue", EquippedFolder)
	DNA.Name = "DNA"
	DNA.Value = "Kid"

	local Tool = Instance.new("StringValue", EquippedFolder)
	Tool.Name = "Tool"
	Tool.Value = "Pencil"

	local Rank = Instance.new("StringValue", EquippedFolder)
	Rank.Name = "Rank"
	Rank.Value = "Stage 1"

	local ValuesFolder = Instance.new("Folder", Player)
	ValuesFolder.Name = "ValuesFolder"

	local TestSize = Instance.new("StringValue", ValuesFolder)
	TestSize.Name = "TestSize"
	TestSize.Value = "0"

	local RealCoins = Instance.new("StringValue", ValuesFolder)
	RealCoins.Name = "RealCoins"
	RealCoins.Value = "0"

	local RobuxSpent = Instance.new("NumberValue", ValuesFolder)
	RobuxSpent.Name = "RobuxSpent"
	RobuxSpent.Value = 0

	local RebirthMultiplier = Instance.new("NumberValue", ValuesFolder)
	RebirthMultiplier.Name = "RebirthMultiplier"
	RebirthMultiplier.Value = 1

	local SizeBoost30X = Instance.new("NumberValue", ValuesFolder)
	SizeBoost30X.Name = "SizeBoost30X"
	SizeBoost30X.Value = 1

	local SizeBoost10X = Instance.new("NumberValue", ValuesFolder)
	SizeBoost10X.Name = "SizeBoost10X"
	SizeBoost10X.Value = 1

	local InSafeZone = Instance.new("BoolValue", ValuesFolder)
	InSafeZone.Name = "InSafeZone"
	InSafeZone.Value = false

	local InBrawl = Instance.new("BoolValue", ValuesFolder)
	InBrawl.Name = "InBrawl"
	InBrawl.Value = false

	local InRing = Instance.new("BoolValue", ValuesFolder)
	InRing.Name = "InRing"
	InRing.Value = false

	RebirthMultiplier.Value = 1

	--Tools / 44

	local ToolsOwned = Instance.new("Folder", Player)
	ToolsOwned.Name = "ToolsOwned"

	for i, v in pairs(game:WaitForChild("ReplicatedStorage"):WaitForChild("Tools"):GetChildren()) do
		local Stat = Instance.new("BoolValue", ToolsOwned)
		Stat.Name = v.Name
		if v.Name == "Pencil" then
			Stat.Value = true
		end
	end

	--Ranks // Stages
	local RanksOwned = Instance.new("Folder", Player)
	RanksOwned.Name = "RanksOwned"

	local Stage1 = Instance.new("BoolValue", RanksOwned)
	Stage1.Name = "Stage 1"
	Stage1.Value = true

	local Stage2 = Instance.new("BoolValue", RanksOwned)
	Stage2.Name = "Stage 2"

	local Stage3 = Instance.new("BoolValue", RanksOwned)
	Stage3.Name = "Stage 3"

	local Stage4 = Instance.new("BoolValue", RanksOwned)
	Stage4.Name = "Stage 4"

	local Stage5 = Instance.new("BoolValue", RanksOwned)
	Stage5.Name = "Stage 5"

	local Stage6 = Instance.new("BoolValue", RanksOwned)
	Stage6.Name = "Stage 6"

	local Stage7 = Instance.new("BoolValue", RanksOwned)
	Stage7.Name = "Stage 7"

	local Stage8 = Instance.new("BoolValue", RanksOwned)
	Stage8.Name = "Stage 8"

	local Stage9 = Instance.new("BoolValue", RanksOwned)
	Stage9.Name = "Stage 9"

	local Stage10 = Instance.new("BoolValue", RanksOwned)
	Stage10.Name = "Stage 10"

	local Stage11 = Instance.new("BoolValue", RanksOwned)
	Stage11.Name = "Stage 11"

	local Stage12 = Instance.new("BoolValue", RanksOwned)
	Stage12.Name = "Stage 12"

	local Stage13 = Instance.new("BoolValue", RanksOwned)
	Stage13.Name = "Stage 13"

	local Stage14 = Instance.new("BoolValue", RanksOwned)
	Stage14.Name = "Stage 14"

	local Stage15 = Instance.new("BoolValue", RanksOwned)
	Stage15.Name = "Stage 15"

	local Stage16 = Instance.new("BoolValue", RanksOwned)
	Stage16.Name = "Stage 16"

	local Stage17 = Instance.new("BoolValue", RanksOwned)
	Stage17.Name = "Stage 17"

	local Stage18 = Instance.new("BoolValue", RanksOwned)
	Stage18.Name = "Stage 18"

	local Stage19 = Instance.new("BoolValue", RanksOwned)
	Stage19.Name = "Stage 19"

	local Stage20 = Instance.new("BoolValue", RanksOwned)
	Stage20.Name = "Stage 20"
	--Dna // Genes // 34
	local DnaOwned = Instance.new("Folder", Player)
	DnaOwned.Name = "DnaOwned"

	local SizeVal2 = Instance.new("NumberValue", ValuesFolder)
	SizeVal2.Name = "SizeVal2"

	local CoinsVal2 = Instance.new("NumberValue", ValuesFolder)
	CoinsVal2.Name = "CoinsVal2"

	local KillStreak = Instance.new("NumberValue", ValuesFolder)
	KillStreak.Name = "KillStreak"

	local IsInBrawl = Instance.new("BoolValue", ValuesFolder)
	IsInBrawl.Name = "IsInBrawl"

	local PetsSettings = Instance.new("Folder", Player)
	PetsSettings.Name = "PetsSettings"

	local MaxPets = Instance.new("NumberValue", PetsSettings)
	MaxPets.Name = "MaxPets"
	MaxPets.Value = 20

	local SecLeftOf30XSize = Instance.new("NumberValue", ValuesFolder)
	SecLeftOf30XSize.Name = "SecLeftOf30XSize"
	SecLeftOf30XSize.Value = 0

	local SecLeftOf10XSize = Instance.new("NumberValue", ValuesFolder)
	SecLeftOf10XSize.Name = "SecLeftOf10XSize"
	SecLeftOf10XSize.Value = 0

	local SecLeftOfAutoSell = Instance.new("NumberValue", ValuesFolder)
	SecLeftOfAutoSell.Name = "SecLeftOfAutoSell"
	SecLeftOfAutoSell.Value = 0

	local AmountOfPets = Instance.new("NumberValue", PetsSettings)
	AmountOfPets.Name = "AmountOfPets"
	AmountOfPets.Value = 0

	local PetsMultiplierSize = Instance.new("NumberValue", PetsSettings)
	PetsMultiplierSize.Name = "PetsMultiplierSize"
	PetsMultiplierSize.Value = 1

	local PetsMultiplierCoins = Instance.new("NumberValue", PetsSettings)
	PetsMultiplierCoins.Name = "PetsMultiplierCoins"
	PetsMultiplierCoins.Value = 1

	local PetsEquipped = Instance.new("NumberValue", PetsSettings)
	PetsEquipped.Name = "PetsEquipped"
	PetsEquipped.Value = 0

	local Settings = Instance.new("Folder", Player)
	Settings.Name = "Settings"

	local Pets = Instance.new("Folder", Player)
	Pets.Name = "Pets"

	local Codes = Instance.new("Folder", Player)
	Codes.Name = "Codes"

	local WalkSpeed = Instance.new("NumberValue", ValuesFolder)
	WalkSpeed.Name = "WalkSpeed"
	WalkSpeed.Value = 24

	local Retrysec = Instance.new("NumberValue", ValuesFolder)
	Retrysec.Name = "Retrysec"
	Retrysec.Value = 2

	local MaxSize = Instance.new("StringValue", ValuesFolder)
	MaxSize.Name = "MaxSize"
	MaxSize.Value = "30"

	local Width = Instance.new("NumberValue", ValuesFolder)
	Width.Name = "Width"
	Width.Value = 0.5

	local Head = Instance.new("NumberValue", ValuesFolder)
	Head.Name = "Head"
	Head.Value = 0.85

	local Height = Instance.new("NumberValue", ValuesFolder)
	Height.Name = "Height"
	Height.Value = 1

	local Depth = Instance.new("NumberValue", ValuesFolder)
	Depth.Name = "Depth"
	Depth.Value = 0.5

	local MaxSizeDesc = Instance.new("NumberValue", ValuesFolder)
	MaxSizeDesc.Name = "MaxSizeDesc"
	MaxSizeDesc.Value = 10

	local TotalSize = Instance.new("StringValue", ValuesFolder)
	TotalSize.Name = "TotalSize"
	TotalSize.Value = "0"

	local Kills = Instance.new("NumberValue", ValuesFolder)
	Kills.Name = "Kills"
	Kills.Value = 0

	local MaxHealth = Instance.new("StringValue", ValuesFolder)
	MaxHealth.Name = "MaxHealth"
	MaxHealth.Value = "100"

	if MS:UserOwnsGamePassAsync(Player.UserId, 47285641) then
		MaxHealth.Value = 200
	end

	local AutoClicking = Instance.new("BoolValue", ValuesFolder)
	AutoClicking.Name = "AutoClicking"
	AutoClicking.Value = false

	local TotalMultiplier = Instance.new("NumberValue", ValuesFolder)
	TotalMultiplier.Name = "TotalMultiplier"
	TotalMultiplier.Value = 1

	local Music = Instance.new("BoolValue", Settings)
	Music.Name = "Music"
	Music.Value = true

	local SFX = Instance.new("BoolValue", Settings)
	SFX.Name = "SFX"
	SFX.Value = true

	local LoadingData = Instance.new("BoolValue", ValuesFolder)
	LoadingData.Name = "LoadingData"
	LoadingData.Value = false

	local Popups = Instance.new("BoolValue", Settings)
	Popups.Name = "Popups"
	Popups.Value = true

	local Sell = Instance.new("BoolValue", Settings)
	Sell.Name = "Sell"
	Sell.Value = true

	local Teleport = Instance.new("BoolValue", Settings)
	Teleport.Name = "Teleport"
	Teleport.Value = true

	local Visits = Instance.new("BoolValue", Codes)
	Visits.Name = "1.5mvisits"

	local Likes = Instance.new("BoolValue", Codes)
	Likes.Name = "5klikes"

	local YoutuberCode = Instance.new("BoolValue", Codes)
	YoutuberCode.Name = "doctorplanezonyt"

	local updatedelay = Instance.new("BoolValue", Codes)
	updatedelay.Name = "updatedelay"

	local sorryfordataloss = Instance.new("BoolValue", Codes)
	sorryfordataloss.Name = "sorryfordataloss"

	local Concealed = Instance.new("BoolValue", ValuesFolder)
	Concealed.Value = false
	Concealed.Name = "Concealed"

	local function CharAdded(Character)
		Player.Character.Humanoid.WalkSpeed = WalkSpeed.Value
		Player.Character.Humanoid.MaxHealth = MaxHealth.Value
		Player.Character.Humanoid.Health = MaxHealth.Value

		Character.Humanoid.DisplayDistanceType = Enum.HumanoidDisplayDistanceType.None
		local ClaimedKills = Instance.new("BoolValue", Character)
		ClaimedKills.Value = false
		ClaimedKills.Name = "ClaimedKills"

		local ClonedTool = game.ReplicatedStorage.Tools[Tool.Value]:Clone()
		ClonedTool.Parent = Player.Backpack

		TweenService:Create(Character.Humanoid.BodyHeightScale, SizeTweenInfo, {Value = Height.Value}):Play()
		TweenService:Create(Character.Humanoid.HeadScale, SizeTweenInfo, {Value = Head.Value}):Play()
		TweenService:Create(Character.Humanoid.BodyWidthScale, SizeTweenInfo, {Value = Width.Value}):Play()
		TweenService:Create(Character.Humanoid.BodyDepthScale, SizeTweenInfo, {Value = Depth.Value}):Play()

		if Concealed.Value == true then
			TweenService:Create(Character.Humanoid.BodyHeightScale, SizeTweenInfo, {Value = 1}):Play()
			TweenService:Create(Character.Humanoid.HeadScale, SizeTweenInfo, {Value = 0.85}):Play()
			TweenService:Create(Character.Humanoid.BodyWidthScale, SizeTweenInfo, {Value = 0.5}):Play()
			TweenService:Create(Character.Humanoid.BodyDepthScale, SizeTweenInfo, {Value = 0.5}):Play()

		end
		Character.Humanoid.Died:Connect(function()
			if InBrawl.Value == true then
				Player.PlayerGui:WaitForChild("PopUps"):WaitForChild("BrawlGUIs"):WaitForChild("MainText!").Text = "Brawl In Progress!"
			end
			InBrawl.Value = false
			AutoClicking.Value = false
			Player.ValuesFolder.InSafeZone.Value = false
		end)
		setCollisionGroupRecursive(Character)

		Character.DescendantAdded:Connect(setCollisionGroup)
		Character.DescendantRemoving:Connect(resetCollisionGroup)
	end
	local data
	local success, errorMessage = pcall(function()
		if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0 then
			data = PlayerData:GetAsync(Player.UserId)
		else 
			repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0
			data = PlayerData:GetAsync(Player.UserId)
		end
	end)

	for i, v in pairs(Player.PlayerGui:WaitForChild("GameShop").MainFrame.Dna1.ToolList:GetChildren()) do
		local dna = Instance.new("BoolValue", DnaOwned)
		dna.Name = v.Name
		if dna.Name == "Kid" then
			dna.Value = true
		end
		print("SuccessDna")
	end

	if data ~= nil and success then
		local s, e = pcall(function()
			if data["TestSize"] == nil then
				if data["Size"] ~= nil then
					TestSize.Value = tostring(data["Size"])
					print("Nil")
				end
			else
				TestSize.Value = data["TestSize"]
				print("NotNil")
			end
			if data["RealCoins"] == nil then
				if data["Coins"] ~= nil then
					RealCoins.Value = tostring(data["Coins"])
					print("Nil")
				end
			else
				RealCoins.Value = data["RealCoins"]
				print("NotNil")
			end


			TotalSize.Value = data["TotalSize"]
			if tonumber(RealCoins.Value) / 1000 >= 1 then
				Coins.Value = Format(tonumber(RealCoins.Value), 1)
			else
				Coins.Value = tonumber(RealCoins.Value)
			end

			Kills.Value = data["Kills"]
			MaxHealth.Value = data["MaxHealth"]
			SizeVal2.Value = data["SizeVal2"]
			CoinsVal2.Value = data["CoinsVal2"]
			Music.Value = data["Music"]
			SFX.Value = data["SFX"]
			Popups.Value = data["Popups"]
			Sell.Value = data["Sell"]
			Teleport.Value = data["Teleport"]
			MaxSizeDesc.Value = data["MaxSizeDesc"]
			Likes.Value = data["1.5mvisits"]
			Visits.Value = data["5klikes"]
			YoutuberCode.Value = data["doctorplanezonyt"]
			updatedelay.Value = data["updatedelay"]
			sorryfordataloss.Value = data["sorryfordataloss"]
			DNA.Value = data["DNA"]
			Tool.Value = data["Tool"]
			Rank.Value = data["Rank"]
			SecLeftOf10XSize.Value = data["SecLeftOf10XSize"]
			SecLeftOf30XSize.Value = data["SecLeftOf30XSize"]
			SecLeftOfAutoSell.Value = data["SecLeftOfAutoSell"]
			Stage2.Value = data["Stage 2"]
			Stage3.Value = data["Stage 3"]
			Stage4.Value = data["Stage 4"]
			Stage5.Value = data["Stage 5"]
			Stage6.Value = data["Stage 6"]
			Stage7.Value = data["Stage 7"]
			Stage8.Value = data["Stage 8"]
			Stage9.Value = data["Stage 9"]
			Stage10.Value = data["Stage 10"]
			Stage11.Value = data["Stage 11"]
			Stage12.Value = data["Stage 12"]
			Stage13.Value = data["Stage 13"]
			Stage14.Value = data["Stage 14"]
			Stage15.Value = data["Stage 15"]
			Stage16.Value = data["Stage 16"]
			Stage17.Value = data["Stage 17"]
			Stage18.Value = data["Stage 18"]
			Stage19.Value = data["Stage 19"]
			Stage20.Value = data["Stage 20"]
			RobuxSpent.Value = data["RobuxSpent"]
			RebirthMultiplier.Value = data["RebirthMultiplier"]
			WalkSpeed.Value = data["WalkSpeed"]
			Concealed.Value = data["Concealed"]
			for i, v in pairs(ToolsOwned:GetChildren()) do
				v.Value = data[v.Name]
			end

			for i, v in pairs(DnaOwned:GetChildren()) do
				v.Value = data[v.Name]
			end
			if data["Height"] > 0 then
				Height.Value = data["Height"]
				Width.Value = data["Width"]
				Head.Value = data["Head"]
				Depth.Value = data["Depth"]
			else
				Height.Value = 1
			end
		end)

		game.ReplicatedStorage.PlayerAdded:FireClient(Player, Coins.Value, Size.Value, Height.Value)
		Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Cash"):WaitForChild("CoinsText").Text = Coins.Value
		Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Strength"):WaitForChild("StrengthText").Text = Size.Value

		if Music.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Concealed.Value == true then
			Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Conceal").Image = "rbxassetid://9184613716"	
		end

		if SFX.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Popups.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Sell.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end

		if Teleport.Value == false then
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton").Image = RedButton
			Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
		end
	elseif success == false and data ~= nil then
		LoadingData.Value = true
		Player.PlayerGui:WaitForChild("PopUps"):WaitForChild("ErrorGettingData").Visible = true
		while LoadingData.Value == true do
			for i = Retrysec.Value, 0, -1 do
				Player.PlayerGui.PopUps.ErrorGettingData.Text = "Data Error, Retrying in: "..i
				wait(1)
			end
			local success, errorMessage = pcall(function()
				if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0 then
					data = PlayerData:GetAsync(Player.UserId)
				else
					repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.GetAsync) > 0
					data = PlayerData:GetAsync(Player.UserId)
				end
			end)
			if success == true then
				LoadingData.Value = false
				Player.PlayerGui.PopUps.ErrorGettingData.Text = "Data Recived"
				Player.PlayerGui.PopUps.ErrorGettingData.TextColor3 = Color3.fromRGB(85, 255, 0)
				local s, e = pcall(function()
					if data["TestSize"] == nil then
						if data["Size"] ~= nil then
							TestSize.Value = tostring(data["Size"])
							print("Nil")
						end
					else
						TestSize.Value = data["TestSize"]
						print("NotNil")
					end

					if data["RealCoins"] == nil then
						if data["Coins"] ~= nil then
							RealCoins.Value = tostring(data["Coins"])
							print("Nil")
						end
					else
						RealCoins.Value = data["RealCoins"]
						print("NotNil")
					end


					TotalSize.Value = data["TotalSize"]
					if tonumber(RealCoins.Value) / 1000 >= 1 then
						Coins.Value = Format(tonumber(RealCoins.Value), 1)
					else
						Coins.Value = tonumber(RealCoins.Value)
					end

					Kills.Value = data["Kills"]
					MaxHealth.Value = data["MaxHealth"]
					SizeVal2.Value = data["SizeVal2"]
					CoinsVal2.Value = data["CoinsVal2"]
					Music.Value = data["Music"]
					SFX.Value = data["SFX"]
					Popups.Value = data["Popups"]
					Sell.Value = data["Sell"]
					Teleport.Value = data["Teleport"]
					MaxSizeDesc.Value = data["MaxSizeDesc"]
					Likes.Value = data["1.5mvisits"]
					Visits.Value = data["5klikes"]
					YoutuberCode.Value = data["DoctorPlanezOnYT"]
					DNA.Value = data["DNA"]
					Tool.Value = data["Tool"]
					Rank.Value = data["Rank"]
					SecLeftOf10XSize.Value = data["SecLeftOf10XSize"]
					SecLeftOf30XSize.Value = data["SecLeftOf30XSize"]
					SecLeftOfAutoSell.Value = data["SecLeftOfAutoSell"]
					Stage2.Value = data["Stage 2"]
					Stage3.Value = data["Stage 3"]
					Stage4.Value = data["Stage 4"]
					Stage5.Value = data["Stage 5"]
					Stage6.Value = data["Stage 6"]
					Stage7.Value = data["Stage 7"]
					Stage8.Value = data["Stage 8"]
					Stage9.Value = data["Stage 9"]
					Stage10.Value = data["Stage 10"]
					Stage11.Value = data["Stage 11"]
					Stage12.Value = data["Stage 12"]
					Stage13.Value = data["Stage 13"]
					Stage14.Value = data["Stage 14"]
					Stage15.Value = data["Stage 15"]
					Stage16.Value = data["Stage 16"]
					Stage17.Value = data["Stage 17"]
					Stage18.Value = data["Stage 18"]
					Stage19.Value = data["Stage 19"]
					Stage20.Value = data["Stage 20"]
					RobuxSpent.Value = data["RobuxSpent"]
					RebirthMultiplier.Value = data["RebirthMultiplier"]
					WalkSpeed.Value = data["WalkSpeed"]
					Concealed.Value = data["Concealed"]
					for i, v in pairs(ToolsOwned:GetChildren()) do
						v.Value = data[v.Name]
					end

					for i, v in pairs(DnaOwned:GetChildren()) do
						v.Value = data[v.Name]
					end
					if data["Height"] > 0 then
						Height.Value = data["Height"]
						Width.Value = data["Width"]
						Head.Value = data["Head"]
						Depth.Value = data["Depth"]
					else
						Height.Value = 1
					end
				end)

				game.ReplicatedStorage.PlayerAdded:FireClient(Player, Coins.Value, Size.Value, Height.Value)
				Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Cash"):WaitForChild("CoinsText").Text = Coins.Value
				Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Strength"):WaitForChild("StrengthText").Text = Size.Value

				if Music.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Music"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Concealed.Value == true then
					Player.PlayerGui:WaitForChild("PlayersGui"):WaitForChild("MainFrame"):WaitForChild("Conceal").Image = "rbxassetid://9184613716"	
				end

				if SFX.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("SFX"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Popups.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("PopupEffects"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Sell.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Sell"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end

				if Teleport.Value == false then
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton").Image = RedButton
					Player.PlayerGui:WaitForChild("Settings"):WaitForChild("MainFrame"):WaitForChild("FrameInside"):WaitForChild("ScrollingFrame"):WaitForChild("Teleport"):WaitForChild("ImageButton"):WaitForChild("TextLabel").Text = "Off"
				end
				Player.PlayerGui.PopUps.ErrorGettingData:TweenPosition(UDim2.new(0.637, 0,1.05, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 1)
			else
				Retrysec.Value *= 2
			end
		end
	end
	if TestSize.Value == "" then
		TestSize.Value = "0"
	end

	if RealCoins.Value == "" then
		RealCoins.Value = "0"
	end
	if Player.EquippedFolder.Rank.Value == "Stage1" then
		Player.EquippedFolder.Rank.Value = "Stage 1"
	end

	RebirthMultiplier = Player.PlayerGui:WaitForChild("GameShop"):WaitForChild("MainFrame"):WaitForChild("Ranks"):WaitForChild("ToolList"):WaitForChild(Player.EquippedFolder.Rank.Value):WaitForChild("Multiplier").Value
	if Player.Character then
		CharAdded(Player.Character)
	end
	Player.CharacterAdded:Connect(CharAdded)
	MaxSize.Value = tostring(Player.PlayerGui:WaitForChild("GameShop"):WaitForChild("MainFrame"):WaitForChild("Dna1"):WaitForChild("ToolList"):WaitForChild(DNA.Value):WaitForChild("Capacity").Value)

	local HasGamepass = MS:UserOwnsGamePassAsync(Player.UserId, 47255723) or MS:UserOwnsGamePassAsync(Player.UserId, 39247959)
	if HasGamepass then
		Player.ValuesFolder.MaxSize.Value = "10000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"
		DNA.Value = "Alien (Inf Size)"
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47255772) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.DoubleCoins.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47255723) or MS:UserOwnsGamePassAsync(Player.UserId, 39247959) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.InfSize.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47255154) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.DoubleSize.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47255750) or MS:UserOwnsGamePassAsync(Player.UserId, 40506548) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.Vip.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47285641) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.DoubleHealth.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47285749) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.DoubleDamage.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47285894) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.DoubleKills.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47285707) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.DoubleSpeed.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 47285922) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.FastLift.OwnedFrame.Visible = true
	end
	
	if MS:UserOwnsGamePassAsync(Player.UserId, 63060736) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.AutoClick.OwnedFrame.Visible = true
	end

	if MS:UserOwnsGamePassAsync(Player.UserId, 63061216) then
		Player.PlayerGui:WaitForChild("ShopUi").MainFrame.ImageLabel.Gamepasses.AutoSell.OwnedFrame.Visible = true
	end

	TestSize.Changed:Connect(function()
		Player.Character.Humanoid.MaxHealth = MaxHealth.Value
		if tonumber(TestSize.Value) > tonumber(MaxSize.Value) then
			Player.PlayerGui.MaxSize.MainFrame:TweenPosition(UDim2.new(0.38, 0,0.26, 0), "Out", "Linear", 0.2)
		end
	end)
	
	local AllValues = {"ValuesFolder", "Settings", "Codes", "DnaOwned", "EquippedFolder", "RanksOwned", "ToolsOwned"}
	local DataFolder = Instance.new("Folder", game.ServerStorage)
	DataFolder.Name = Player.Name
	for i, v in pairs(AllValues) do
		local Folder = Instance.new("Folder", DataFolder)
		Folder.Name = v
		for Index, Value in pairs(Player[v]:GetChildren()) do
			local ClonedValue = Value:Clone()
			ClonedValue.Parent = Folder
			ClonedValue.Value = Value.Value
		end
	end
	
	local AllValues = {"ValuesFolder", "Settings", "Codes", "DnaOwned", "EquippedFolder", "RanksOwned", "ToolsOwned"}

	local function FindValue(plr, v)
		for i, l in pairs(AllValues) do
			for i, p in pairs(plr[l]:GetChildren()) do
				if p.Name == v.Name then
					print(p.Value)
					return p.Value
				end
			end
		end
	end
	
	for i, v in pairs(game.ServerStorage:WaitForChild(Player.Name):GetDescendants()) do
		if v.ClassName == "NumberValue" or v.ClassName == "IntValue" or v.ClassName == "BoolValue" or v.ClassName == "StringValue" then
			v.Value = FindValue(Player, v)
			wait(0.002)
		end
	end

	BS:AwardBadge(Player.UserId, 2126551692)
	if tonumber(TestSize.Value) >= 100 then
		MaxSizeDesc.Value = 2
	end
	if tonumber(TestSize.Value)>= 100 then
		MaxSizeDesc.Value = 3.5
	end
	if tonumber(TestSize.Value) >= 5000 then
		MaxSizeDesc.Value = 5
	end
	if tonumber(TestSize.Value) >= 10000 then
		MaxSizeDesc.Value = 7
	end
	if tonumber(TestSize.Value) >= 15000 then
		MaxSizeDesc.Value = 9
	end
	if tonumber(TestSize.Value) >= 25000 then
		MaxSizeDesc.Value = 12
	end
	if tonumber(TestSize.Value) >= 50000 then
		MaxSizeDesc.Value = 16
	end

	if tonumber(TestSize.Value) >= 500000 then
		MaxSizeDesc.Value = 20
	end

	if tonumber(TestSize.Value) >= 1000000 then
		MaxSizeDesc.Value = 25
	end

	if tonumber(TestSize.Value) >= 250000000 then
		MaxSizeDesc.Value = 35
	end

	if tonumber(TestSize.Value) >= 500000000 then
		MaxSizeDesc.Value = 40
	end

	if tonumber(TestSize.Value) >= 25000000000 then
		MaxSizeDesc.Value = 45
	end

	if tonumber(TestSize.Value) >= 50000000000 then
		MaxSizeDesc.Value = 50
	end

	if  tonumber(TestSize.Value) >= 500000000000 then
		MaxSizeDesc.Value = 55
	end

	if  tonumber(TestSize.Value) >= 1000000000000 then
		MaxSizeDesc.Value = 60
	end

	if tonumber(TestSize.Value) >= 25000000000000 then
		MaxSizeDesc.Value = 65
	end

	if tonumber(TestSize.Value) >= 50000000000000 then
		MaxSizeDesc.Value = 70
	end

	if tonumber(TestSize.Value) >= 100000000000000 then
		MaxSizeDesc.Value = 75
	end

	if tonumber(TestSize.Value) >= 250000000000000 then
		MaxSizeDesc.Value = 80
	end

	if tonumber(TestSize.Value) >= 750000000000000 then
		MaxSizeDesc.Value = 85
	end

	if tonumber(TestSize.Value) >= 1000000000000000 then
		MaxSizeDesc.Value = 90
	end

	TestSize.Changed:Connect(function()
		if tonumber(TestSize.Value) >= 100 then
			MaxSizeDesc.Value = 2
		end
		if tonumber(TestSize.Value)>= 100 then
			MaxSizeDesc.Value = 3.5
		end
		if tonumber(TestSize.Value) >= 5000 then
			MaxSizeDesc.Value = 5
		end
		if tonumber(TestSize.Value) >= 10000 then
			MaxSizeDesc.Value = 7
		end
		if tonumber(TestSize.Value) >= 15000 then
			MaxSizeDesc.Value = 9
		end
		if tonumber(TestSize.Value) >= 25000 then
			MaxSizeDesc.Value = 12
		end
		if tonumber(TestSize.Value) >= 50000 then
			MaxSizeDesc.Value = 16
		end

		if tonumber(TestSize.Value) >= 500000 then
			MaxSizeDesc.Value = 20
		end

		if tonumber(TestSize.Value) >= 1000000 then
			MaxSizeDesc.Value = 25
		end

		if tonumber(TestSize.Value) >= 250000000 then
			MaxSizeDesc.Value = 35
		end

		if tonumber(TestSize.Value) >= 500000000 then
			MaxSizeDesc.Value = 40
		end

		if tonumber(TestSize.Value) >= 25000000000 then
			MaxSizeDesc.Value = 45
		end

		if tonumber(TestSize.Value) >= 50000000000 then
			MaxSizeDesc.Value = 50
		end

		if  tonumber(TestSize.Value) >= 500000000000 then
			MaxSizeDesc.Value = 55
		end

		if  tonumber(TestSize.Value) >= 1000000000000 then
			MaxSizeDesc.Value = 60
		end

		if tonumber(TestSize.Value) >= 25000000000000 then
			MaxSizeDesc.Value = 65
		end

		if tonumber(TestSize.Value) >= 50000000000000 then
			MaxSizeDesc.Value = 70
		end

		if tonumber(TestSize.Value) >= 100000000000000 then
			MaxSizeDesc.Value = 75
		end

		if tonumber(TestSize.Value) >= 250000000000000 then
			MaxSizeDesc.Value = 80
		end

		if tonumber(TestSize.Value) >= 750000000000000 then
			MaxSizeDesc.Value = 85
		end

		if tonumber(TestSize.Value) >= 1000000000000000 then
			MaxSizeDesc.Value = 90
		end
	end)
	
	BS:AwardBadge(Player.UserId, 2125929662)

	
	while wait() do
		if Stage2.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 3"].LockBackground.Visible = false
		end
		if Stage3.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 4"].LockBackground.Visible = false
		end
		if Stage4.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 5"].LockBackground.Visible = false
		end
		if Stage5.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 6"].LockBackground.Visible = false
		end
		if Stage6.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 7"].LockBackground.Visible = false
		end
		if Stage7.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 8"].LockBackground.Visible = false
		end
		if Stage8.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 9"].LockBackground.Visible = false
		end
		if Stage9.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 10"].LockBackground.Visible = false
		end
		if Stage10.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 11"].LockBackground.Visible = false
		end

		if Stage11.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 12"].LockBackground.Visible = false
		end

		if Stage12.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 13"].LockBackground.Visible = false
		end

		if Stage13.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 14"].LockBackground.Visible = false
		end

		if Stage14.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 15"].LockBackground.Visible = false
		end

		if Stage15.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 16"].LockBackground.Visible = false
		end

		if Stage16.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 17"].LockBackground.Visible = false
		end

		if Stage17.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 18"].LockBackground.Visible = false
		end

		if Stage18.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 19"].LockBackground.Visible = false
		end

		if Stage19.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 20"].LockBackground.Visible = false
		end


		--CheckIfYouOwnTheStage



		if Stage3.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 3"].LockBackground.Visible = false
		end

		if Stage4.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 4"].LockBackground.Visible = false
		end

		if Stage5.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 5"].LockBackground.Visible = false
		end

		if Stage6.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 6"].LockBackground.Visible = false
		end

		if Stage7.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 7"].LockBackground.Visible = false
		end

		if Stage8.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 8"].LockBackground.Visible = false
		end

		if Stage9.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 9"].LockBackground.Visible = false
		end

		if Stage10.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 10"].LockBackground.Visible = false
		end

		if Stage11.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 11"].LockBackground.Visible = false
		end

		if Stage12.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 12"].LockBackground.Visible = false
		end

		if Stage13.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 13"].LockBackground.Visible = false
		end

		if Stage14.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 14"].LockBackground.Visible = false
		end

		if Stage15.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 15"].LockBackground.Visible = false
		end

		if Stage16.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 16"].LockBackground.Visible = false
		end

		if Stage17.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 17"].LockBackground.Visible = false
		end

		if Stage18.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 18"].LockBackground.Visible = false
		end

		if Stage19.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 19"].LockBackground.Visible = false
		end

		if Stage20.Value == true then
			Player.PlayerGui.GameShop.MainFrame.Ranks.ToolList["Stage 20"].LockBackground.Visible = false
		end

		if tonumber(TestSize.Value) / 1000 >= 1 then
			Size.Value = Format(tonumber(TestSize.Value), 1)
		else
			Size.Value = TestSize.Value
		end

		if tonumber(RealCoins.Value) / 1000 >= 1 then
			Coins.Value = Format(tonumber(RealCoins.Value), 1)
		else
			Coins.Value = RealCoins.Value
		end
		if Player.Character then
			Player.ValuesFolder.RebirthMultiplier.Value = RebirthValues[Stage.Value]
			Player.Character.Humanoid.MaxHealth = MaxHealth.Value
			Player.Character.Humanoid.WalkSpeed = SpeedTable[Stage.Value]
			Player.ValuesFolder.WalkSpeed.Value = SpeedTable[Stage.Value]
			if MS:UserOwnsGamePassAsync(Player.UserId, 47285707) then
				Player.Character.Humanoid.WalkSpeed = SpeedTableX2[Stage.Value]
				Player.ValuesFolder.WalkSpeed.Value = SpeedTableX2[Stage.Value]
			end
		end
		
		
		
		SizeVal2.Value = math.floor(tonumber(TotalSize.Value) / 100000000000000000000000000000)
		CoinsVal2.Value = math.floor(tonumber(RealCoins.Value) /100000000000000000000000000000)
		Stage.Value = Rank.Value
	end

end)

local function TableValues(Player)
	local Player_stats = {}

	for i, v in pairs(Player.ValuesFolder:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.Settings:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.Codes:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.DnaOwned:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.EquippedFolder:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.RanksOwned:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	for i, v in pairs(Player.ToolsOwned:GetChildren()) do
		Player_stats[v.Name] = v.Value
	end

	return Player_stats
end
game.Players.PlayerRemoving:Connect(function(Player)
	local Name = Player.Name
	if Player.ValuesFolder.LoadingData.Value == false then
		local Key = Player.UserId
		local Table = TableValues(game.ServerStorage[Name])
		if Table ~= TableValues(game.ServerStorage.DefaultData) then
			print()
			local S, E = pcall(function()
				for i, v in pairs(game.Players:GetChildren()) do
					local Table = TableValues(v)
					local S, E = pcall(function()
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						else
							repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end)
					if S then
						print("DataStored")
					else
						warn(E.." attempting retry...")
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							task.wait(6)
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end
				end
			end)
	--		game.ServerStorage[Name]:Destroy()
			if S then
				print("DataStored")
			else
				warn(E)
			end
		end
	else
		print("Data Wasn't Loaded")
	end
end)

Well it was above 50k chars so i had to cut the rest

1 Like

alr i sent you it. Could you check it out?

1 Like

I think I might have a theory. Observe this part of the script:

		local Key = Player.UserId
		local Table = TableValues(game.ServerStorage[Name])
		if Table ~= TableValues(game.ServerStorage.DefaultData) then
			print()
			local S, E = pcall(function()
				for i, v in pairs(game.Players:GetChildren()) do
					local Table = TableValues(v)
					local S, E = pcall(function()
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						else
							repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end)
					if S then
						print("DataStored")
					else
						warn(E.." attempting retry...")
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							task.wait(6)
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end
				end
			end)
			--		game.ServerStorage[Name]:Destroy()
			if S then
				print("DataStored")
			else
				warn(E)
			end
		end

By what I am seeing you are setting the key before the for loop. Before explaining the problem I think is happening let’s say there are 2 players:

  • Player1
  • Player2

If we are saving data from Player1 then the key will be “Player1”. We will start looping and we will find Player1 first, then in this for loop:

				for i, v in pairs(game.Players:GetChildren()) do
					local Table = TableValues(v)
					local S, E = pcall(function()
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						else
							repeat task.wait(1) until DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end)
					if S then
						print("DataStored")
					else
						warn(E.." attempting retry...")
						if DataStoresService:GetRequestBudgetForRequestType(Enum.DataStoreRequestType.SetIncrementAsync) > 0 then
							task.wait(6)
							PlayerData:UpdateAsync(Key, function(Key, OldValue)
								return Table
							end)
						end
					end
				end

we set the data. However, the for loop will keep going on, this means that it will then reach Player2 and get the data from Player2 and save it into Player1. Either way I recommend you to add a Log system. Basically make a module that is the data store service except any call like :UpdateAsync or :GetAsync will be logged on a Log database. Then you can trace what happened to a specific player.

I tried to fix it by making loading data true until you’ve recieved the data as it wasn’t like that normally

The problem isn’t that you are making loading data false/true. I think the problem is you are looping in players.

  • Player1
  • Player2
  • Player3

When you loop with these 3 players trying to set the data for player1 at the end of the loop you will set the data for player1 with player3. Since you are looping in players.