Datastore2 not saving values

I’m using datastore in my game and everything worked until it randomly didn’t.
Im using ordereddatastores but for some reason new data just don’t save for some values. I modified my script and it worked for a bit but then broke again and I have no idea what to do. Heres my script:

local Players = game:GetService("Players")
local ServerScriptService = game:GetService("ServerScriptService")
local Workspace = game:GetService("Workspace")
local DataStore2 = require(ServerScriptService.DataStore.DataStore2)
local ReplicatedStorage = game:GetService("ReplicatedStorage")

DataStore2.Combine(
	"DATA",
	"Speed",
	"Jump",
	"Strength",
	"LastPlayed",
	"Health",
	"Played",
	"Wins",
	"Challenge",
	"World", 
	"Spin",
	"Time",
	"Weights",
	"ReallyPlayed",
	"Time2",
	"CanClaim"
)


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

	--task.wait() -- for dif script to be able to load with this
	local char = player.Character or player.CharacterAdded:Wait()
	local SpeedStore = DataStore2("Speed", player)
	local JumpStore = DataStore2("Jump", player)
	local StrengthStore = DataStore2("Strength", player)
	local PlayedStore = DataStore2("Played", player)
	local WinsStore = DataStore2("Wins", player)
	local HealthStore = DataStore2("Health", player)
	local ChallengeStore = DataStore2("Challenge", player)
	local WorldStore = DataStore2("World", player)
	local WeightsStore = DataStore2("Weights", player)
	local SpinStore = DataStore2("Spin", player)
	local TimeStore = DataStore2("Time", player)
	local Time2Store = DataStore2("Time2", player)
	local LastPlayedStore = DataStore2("LastPlayed", player)
	local ReallyplayedStore = DataStore2("ReallyPlayed", player)
	local CanClaimStore = DataStore2("CanClaim", player)

	char:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(107.75, 10.5, 483.75)

	char:WaitForChild("HumanoidRootPart").CustomPhysicalProperties = PhysicalProperties.new(60, 0, 0)
	local leaderstats = Instance.new("Folder")
	local InvisStats = Instance.new("Folder")
	local NonSaveValues = player:WaitForChild("NonSaveValues")
	InvisStats.Parent = player
	InvisStats.Name = "InvisStats"
	leaderstats.Parent = player
	leaderstats.Name = "leaderstats"

	local WeightsFolder = Instance.new("Folder")
	WeightsFolder.Parent = char
	WeightsFolder.Name = "WeightsFolder"

	--

	local currmulti = Instance.new("NumberValue")
	currmulti.Parent = InvisStats
	currmulti.Value = 1
	currmulti.Name = "CurrentMulti"
	--
	local IsOpeningEgg = Instance.new("BoolValue")
	IsOpeningEgg.Value = false
	IsOpeningEgg.Parent = InvisStats
	IsOpeningEgg.Name = "IsOpeningEgg"

	local PetsEquipped = Instance.new("IntValue")
	PetsEquipped.Parent = InvisStats
	PetsEquipped.Name = "PetsEquipped"
	PetsEquipped.Value = 0



	local Weights = Instance.new("IntValue")
	Weights.Name = "Weights"

	Weights.Value = WeightsStore:Get(0)
	Weights.Parent = InvisStats

	local GuiOpen = Instance.new("StringValue")
	GuiOpen.Name = "GuiOpen"

	GuiOpen.Value = "nil"
	GuiOpen.Parent = NonSaveValues

	local Challenge = Instance.new("IntValue")
	Challenge.Name = "Challenge"

	Challenge.Value = ChallengeStore:Get(0)
	Challenge.Parent = InvisStats

	local Max1 = Instance.new("BoolValue")
	Max1.Name = "Max1"

	Max1.Value = true
	Max1.Parent = InvisStats

	local World = Instance.new("IntValue")
	World.Name = "World"

	World.Value = WorldStore:Get(0)
	World.Parent = InvisStats

	if World.Value == 1 then
		if not game.Teams:FindFirstChild("World2") then
			game:WaitForChild("ReplicatedStorage").World2.Parent = game.Teams
			player.Team = game.Teams.World2
		else
			player.Team = game.Teams.World2
		end 

		char.HumanoidRootPart.CFrame = CFrame.new(-3271.378, 15.142, -400.74)
	elseif World.Value == 0 then
		if not game.Teams:FindFirstChild("World1") then
			game:WaitForChild("ReplicatedStorage").World1.Parent = game.Teams
			player.Team = game.Teams.World1
		else
			player.Team = game.Teams.World1
		end 
		char:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(107.75, 10, 423.75)
	elseif World.Value == 3 then
		if not game.Teams:FindFirstChild("World3") then
			game:WaitForChild("ReplicatedStorage").World3.Parent = game.Teams
			player.Team = game.Teams.World3
		else
			player.Team = game.Teams.World3
		end 
		char:WaitForChild("HumanoidRootPart").CFrame = CFrame.new(-3271.378, 15.142, -400.74)
	end

	local Punching = Instance.new("BoolValue")
	Punching.Name = "Punching"

	Punching.Value = false
	Punching.Parent = InvisStats

	local LastPlayed = Instance.new("NumberValue")
	LastPlayed.Name = "LastPlayed"

	LastPlayed.Value = LastPlayedStore:Get(0)
	LastPlayed.Parent = InvisStats



	local Spin = Instance.new("IntValue")
	Spin.Name = "Spin"

	Spin.Value = SpinStore:Get(1)
	Spin.Parent = InvisStats

	local Max2 = Instance.new("BoolValue")
	Max2.Name = "Max2"

	Max2.Value = true
	Max2.Parent = InvisStats

	local DoubleRegen = Instance.new("BoolValue")
	DoubleRegen.Name = "DoubleRegen"
	DoubleRegen.Parent = NonSaveValues

	local DoubleWins = Instance.new("BoolValue")
	DoubleWins.Name = "DoubleWins"
	DoubleWins.Parent = NonSaveValues

	local VIP = Instance.new("BoolValue")
	VIP.Name = "VIP"
	VIP.Parent = NonSaveValues

	local Wins = Instance.new("IntValue")
	Wins.Name = "Wins"

	Wins.Value = WinsStore:Get(0)
	Wins.Parent = leaderstats

	local Jump = Instance.new("NumberValue")
	Jump.Name = "Jump"

	Jump.Value = JumpStore:Get(0)
	Jump.Parent = InvisStats

	local Strength = Instance.new("NumberValue")
	Strength.Name = "Strength"

	Strength.Value = StrengthStore:Get(0)
	Strength.Parent = InvisStats

	local Time = Instance.new("IntValue")
	Time.Name = "Time"
	Time.Value = TimeStore:Get(0)  -- Use 0 as default value
	Time.Parent = InvisStats

	local Time2 = Instance.new("IntValue")
	Time2.Name = "Time2"

	Time2.Value = Time2Store:Get(0)  -- Use 0 as default value
	
	Time2.Parent = InvisStats


	local instrength = Instance.new("IntValue")
	instrength.Name = "InStrength"

	instrength.Parent = InvisStats
	instrength.Value = 0 --im so happy!-- skibbidi toilet rizz

	local Health = Instance.new("NumberValue")--
	Health.Name = "Health"

	Health.Value = HealthStore:Get(10) 

	Health.Parent = InvisStats
	char:WaitForChild("Humanoid").MaxHealth = Health.Value + 10
	char:WaitForChild("Humanoid").Health = Health.Value + 10


	local Speed = Instance.new("NumberValue")
	Speed.Name = "Speed"

	Speed.Value = SpeedStore:Get(0)
	Speed.Parent = InvisStats

	local ActiveSpeed = Instance.new("NumberValue")
	ActiveSpeed.Name = "ActiveSpeed"

	ActiveSpeed.Value = Speed.Value
	ActiveSpeed.Parent = InvisStats

	local ActiveJump = Instance.new("NumberValue")
	ActiveJump.Name = "ActiveJump"

	ActiveJump.Value = Jump.Value
	ActiveJump.Parent = InvisStats


	if Speed.Value > 100 then
		char:FindFirstChild("Humanoid").WalkSpeed = 50
	else
		--if Speed.Value <= 50 then
		char:FindFirstChild("Humanoid").WalkSpeed = Speed.Value * 0.6 + 16
		--else
		--	char:FindFirstChild("Humanoid").WalkSpeed = 0.2*(Speed.Value - 50) + 40 + 16
		--end
	end

	local played = Instance.new("BoolValue")
	played.Name = "Played"

	played.Value = PlayedStore:Get(false)
	played.Parent = InvisStats


	local ReallyPlayed = Instance.new("BoolValue")
	ReallyPlayed.Name = "ReallyPlayed"

	ReallyPlayed.Value = ReallyplayedStore:Get(false)
	ReallyPlayed.Parent = InvisStats

	local CanClaim = Instance.new("BoolValue") 
	CanClaim.Parent = InvisStats
	CanClaim.Value = CanClaimStore:Get(false)
	CanClaim.Name = "CanClaim"


	if player:IsInGroup(12257370) then
		game.ReplicatedStorage.ClaimChest:FireClient(player, "Timer")
		if Time2.Value == 0 then
			CanClaim = true
		end
	end

	local inarea = Instance.new("BoolValue")
	inarea.Name = "InArea"
	inarea.Value = false

	inarea.Parent = InvisStats


	if Jump.Value > 150 then
		char:FindFirstChild("Humanoid").JumpPower = 135
	else
		if Jump.Value > 100 then
			char:FindFirstChild("Humanoid").JumpPower = 0.15*(Jump.Value - 100) + 125 
		else
			char:FindFirstChild("Humanoid").JumpPower = Jump.Value + 25
		end
	end


	player.CharacterAdded:Connect(function(char)

		local WeightsFolder = Instance.new("Folder")
		WeightsFolder.Parent = char
		WeightsFolder.Name = "WeightsFolder"

		char:WaitForChild("HumanoidRootPart").CustomPhysicalProperties = PhysicalProperties.new(60, 0, 0)



		char:WaitForChild("Humanoid").MaxHealth = Health.Value + 10
		char:WaitForChild("Humanoid").Health = Health.Value + 10


		if Jump.Value > 150 then
			char:FindFirstChild("Humanoid").JumpPower = 110
		else
			if Jump.Value > 100 then
				char:FindFirstChild("Humanoid").JumpPower = 0.15*(Jump.Value - 100) + 125 
			else
				char:FindFirstChild("Humanoid").JumpPower = Jump.Value + 25
			end
		end
		if Speed.Value > 100 then
			char:FindFirstChild("Humanoid").WalkSpeed = 50 
		else
			if Speed.Value <= 50 then
				char:FindFirstChild("Humanoid").WalkSpeed = Speed.Value * 0.6 + 16
				--else
				--	char:FindFirstChild("Humanoid").WalkSpeed = 0.2*(Speed.Value - 50) + 40 + 16
			end
		end

	end)


	player:GetPropertyChangedSignal("Parent"):Connect(function()
		Workspace.PlayerPets[player.Name]:Destroy()
	end)
	--SpeedStore:OnUpdate(function(newPoints)
	--	Speed.Value = newPoints
	--end)
	----
	--PlayedStore:OnUpdate(function(newPoints)
	--	played.Value = newPoints
	--end)
	----
	--JumpStore:OnUpdate(function(newPoints)
	--	Jump.Value = newPoints
	--end)

	local LastSpeedValue = Speed.Value
	ActiveSpeed.Value = Speed.Value




	Speed.Changed:Connect(function()
		if ActiveSpeed.Value >= LastSpeedValue then
			LastSpeedValue = Speed.Value
			ActiveSpeed.Value = LastSpeedValue
		end

		SpeedStore:Set(player.InvisStats.Speed.Value)
		--if player.InvisStats.Max1.Value == true then
		if Speed.Value < 100 then
			if Speed.Value <= 50 then
				char:FindFirstChild("Humanoid").WalkSpeed += 0.8
			else
				char:FindFirstChild("Humanoid").WalkSpeed += 0.2
			end
		end
		--end
	end)

	game:WaitForChild("ReplicatedStorage").SetSpeed.OnServerEvent:Connect(function(plr, amt, bool)
		--player.InvisStats.Max1.Value = bool
		if amt ~= nil and amt <= Speed.Value then
			ActiveSpeed.Value = amt
		end
		if bool == true then
			ActiveSpeed.Value = Speed.Value
		end
	end)

	local LastJumpValue = Jump.Value

	Jump.Changed:Connect(function()
		if ActiveJump.Value >= LastJumpValue then
			LastJumpValue = Jump.Value
			ActiveJump.Value = LastJumpValue
		end
		JumpStore:Set(player.InvisStats.Jump.Value)
		--if player.InvisStats.Max2.Value == true then
		if Jump.Value < 150 then
			if Jump.Value < 100 then
				char:FindFirstChild("Humanoid").JumpPower += 1 
			else
				char:FindFirstChild("Humanoid").JumpPower += 0.2
			end
		end
		--end
	end)

	game:WaitForChild("ReplicatedStorage").SetJump.OnServerEvent:Connect(function(plr, amt, bool)
		--player.InvisStats.Max2.Value = bool
		if amt ~= nil and amt <= Jump.Value then
			ActiveJump.Value = amt 
		end
		if bool == true then	
			ActiveJump.Value = Jump.Value
		end
	end)

	played.Changed:Connect(function()
		PlayedStore:Set(player.InvisStats.Played.Value)
		print(PlayedStore:Set(player.InvisStats.Played.Value))
		print(player.InvisStats.Played.Value)
		print(PlayedStore:Get())
	end)

	Health.Changed:Connect(function()
		HealthStore:Set(player.InvisStats.Health.Value)
	end)

	Strength.Changed:Connect(function()
		StrengthStore:Set(player.InvisStats.Strength.Value)
	end)

	Wins.Changed:Connect(function()
		WinsStore:Set(player.leaderstats.Wins.Value)
	end)
	World.Changed:Connect(function()
		WorldStore:Set(player.InvisStats.World.Value)
		if World.Value == 1 then
			player.Team = game.Teams:WaitForChild("World2")
			game:WaitForChild("ReplicatedStorage").GotWorld2:FireClient(player)
		elseif World.Value == 0 then
			player.Team = game.Teams:WaitForChild("World1")
		end
	end)

	Challenge.Changed:Connect(function()
		ChallengeStore:Set(player.InvisStats.Challenge.Value)
		print(ChallengeStore:Set(player.InvisStats.Challenge.Value))
		print(ChallengeStore:Get())
		print(player.InvisStats.Challenge.Value)
	end)


	Spin.Changed:Connect(function()
		SpinStore:Set(Spin.Value)
	end)

	TimeStore:OnUpdate(function(newTime)
		Time.Value = newTime
	end)

	Time2Store:OnUpdate(function(newTime2)
		Time2.Value = newTime2
	end)



	LastPlayedStore:OnUpdate(function(newLastPlayed)
		LastPlayed.Value = newLastPlayed
	end)

	ReallyPlayed.Changed:Connect(function()
		ReallyplayedStore:Set(ReallyPlayed.Value)
	end)

	Weights.Changed:Connect(function()
		WeightsStore:Set(Weights.Value)
	end)


	CanClaimStore:OnUpdate(function(newCanClaim)
		CanClaim.Value = newCanClaim
	end)

	
	
	
end)

I read every single forum and my code shouldn’t break but it does. someone please help because my game has hundreds of ccu and everyone is hating it because their data isn’t saving properly.

1 Like

A reason could BE that Roblox sets strict data retrieval and write limits per second for data storage. If these limits are exceeded, writes may be blocked or not performed.