Sometimes the IPA request is failing for a player that joins the game. Can someone tell how to fix this?


local DataStore = game:GetService("DataStoreService")
local ds1 = DataStore:GetDataStore("YumsSave")
local ds2 = DataStore:GetDataStore("BurgerSave")
local ds3 = DataStore:GetDataStore("Rebirthsave")
local ds4 = DataStore:GetDataStore("Petvaluesave")
local ds5 = DataStore:GetDataStore("PetSave")
local ds6 = DataStore:GetDataStore("PetSavevalue")
local ds7 = DataStore:GetDataStore("PetSavevalue2")
local ds8 = DataStore:GetDataStore("PetSavevalue3")
local ds9 = DataStore:GetDataStore("PetSavevalue4")
local ds10 = DataStore:GetDataStore("PetSavevalue5")
local ds11 = DataStore:GetDataStore("PetSavevalue6")
local try = 0

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

	print("stats")
local leader = Instance.new("Folder")
leader.Name = "leaderstats"
leader.Parent = player
	
local pet = Instance.new("NumberValue")
	pet.Name = "petvalue"
	pet.Parent = player
	pet.Value = ds4:GetAsync(player.UserId)
	ds4:SetAsync(player.UserId, pet.Value)
	print("pet value loaded")
	
local Yums = Instance.new("IntValue")
	Yums.Name = "Yums"
	Yums.Parent = leader
    Yums.Value = ds1:GetAsync(player.UserId)
	ds1:SetAsync(player.UserId, Yums.Value) 
	print("Yums loaded")
	print(script.Parent)
	wait(75)
local burger = Instance.new("IntValue")
	burger.Name = "burger"
	burger.Parent = leader
    burger.Value = ds2:GetAsync(player.UserId) 
	ds2:SetAsync(player.UserId, burger.Value)
	print("burger level loaded")
	
local rebirth = Instance.new("IntValue")
	rebirth.Name = "Rebirth"
	rebirth.Parent = leader
	rebirth.Value = ds3:GetAsync(player.UserId)
	ds3:SetAsync(player.UserId, rebirth.Value)
	print("rebirths")
	
	local pets = Instance.new("Folder")
	pets.Name = "pets"
	pets.Parent = leader
	
	local petone = Instance.new("IntValue")
	petone.Value = ds6:GetAsync(player.UserId)
	ds6:SetAsync(player.UserId, petone.Value)
	petone.Parent = pets
	petone.Name = "one"
	print("pet1 loaded")
	
	local pettwo = Instance.new("IntValue")
	pettwo.Value = ds7:GetAsync(player.UserId)
	ds7:SetAsync(player.UserId, pettwo.Value)
	pettwo.Parent = pets
	pettwo.Name = "two"
	print("pet2 loaded")
	
	local petthree = Instance.new("IntValue")
	petthree.Value = ds8:GetAsync(player.UserId) 
	ds8:SetAsync(player.UserId, petthree.Value)
	petthree.Parent = pets
	petthree.Name = "three"
	print("pet3 loaded")
	
	local petfour = Instance.new("IntValue")
	petfour.Value = ds9:GetAsync(player.UserId) 
	ds9:SetAsync(player.UserId, petfour.Value)
	petfour.Parent = pets
	petfour.Name = "four"
	print("pet4 loaded")
	
	local petfive = Instance.new("IntValue")
	petfive.Value = ds10:GetAsync(player.UserId) 
	ds10:SetAsync(player.UserId, petfive.Value)
	petfive.Parent = pets
	petfive.Name = "five"
	print("pet5 loaded")
	
	local petsix = Instance.new("IntValue")
	petsix.Value = ds11:GetAsync(player.UserId) 
	ds11:SetAsync(player.UserId, petsix.Value)
	petsix.Parent = pets
	petsix.Name = "six"
	print("pet6 loaded")
	
	petone.Changed:Connect(function()
		ds6:SetAsync(player.UserId, petone.Value)
		if ds6:GetAsync(player.UserId, petone.Value) == petone.Value then
			print("saved")
		end
	end)
	
	pettwo.Changed:Connect(function()
		ds7:SetAsync(player.UserId, pettwo.Value)
		if ds7:GetAsync(player.UserId, pettwo.Value) == pettwo.Value then
			print("saved")
		end
	end)
	
	petthree.Changed:Connect(function()
		ds8:SetAsync(player.UserId, petthree.Value)
		if ds8:GetAsync(player.UserId, petthree.Value) == petthree.Value then
			print("saved")
		end
	end)
	
	petfour.Changed:Connect(function()
		ds9:SetAsync(player.UserId, petfour.Value)
		if ds9:GetAsync(player.UserId, petfour.Value) == petfour.Value then
			print("saved")
		end
	end)
	
	petfive.Changed:Connect(function()
		ds10:SetAsync(player.UserId, petfive.Value)
		if ds10:GetAsync(player.UserId, petfive.Value) == petfive.Value then
			print("saved")
		end
	end)
	
	petsix.Changed:Connect(function()
		ds11:SetAsync(player.UserId, petsix.Value)
		if ds11:GetAsync(player.UserId, petsix.Value) == petsix.Value then
			print("saved")
		end
	end)
	
	Yums.Changed:Connect(function()
		ds1:SetAsync(player.UserId, Yums.Value)
		if ds1:GetAsync(player.UserId, Yums.Value) == Yums.Value then
			print("saved")
		end
		ds2:SetAsync(player.UserId, burger.Value)
		if ds2:GetAsync(player.UserId, Yums.Value) == Yums.Value then
			print("saved")
		end
		ds3:SetAsync(player.UserId, rebirth.Value)
		if ds3:GetAsync(player.UserId, rebirth.Value) == rebirth.Value then
			print("saved")
		end
		
		ds6:SetAsync(player.UserId, petone.Value)
		if ds6:GetAsync(player.UserId, petone.Value) == petone.Value then
			print("saved")
		end
		
		ds7:SetAsync(player.UserId, pettwo.Value)
		if ds7:GetAsync(player.UserId, pettwo.Value) == pettwo.Value then
			print("saved")
		end
		
		ds8:SetAsync(player.UserId, petthree.Value)
		if ds8:GetAsync(player.UserId, petthree.Value) == petthree.Value then
			print("saved")
		end
		
		ds9:SetAsync(player.UserId, petfour.Value)
		if ds9:GetAsync(player.UserId, petfour.Value) == petfour.Value then
			print("saved")
		end
		
		ds10:SetAsync(player.UserId, petfive.Value)
		if ds10:GetAsync(player.UserId, petfive.Value) == petfive.Value then
			print("saved")
		end
		
		ds11:SetAsync(player.UserId, petsix.Value)
		if ds11:GetAsync(player.UserId, petsix.Value) == petsix.Value then
			print("saved")
		end
		
end)
	burger.Changed:Connect(function()
		ds2:SetAsync(player.UserId, burger.Value)
		if ds2:GetAsync(player.UserId, Yums.Value) == Yums.Value then
			print("saved")
		end
	end)
	
	
	rebirth.Changed:connect(function()
		ds3:SetAsync(player.UserId, rebirth.Value)
		if ds3:GetAsync(player.UserId, rebirth.Value) == rebirth.Value then
			print("saved")
		end
	end)
	game.Players.PlayerAdded:Connect(function(plr)
		plr.CharacterAdded:Connect(function(char)
			char.Changed:Connect(function()
				ds4:SetAsync(player.UserId, pet.Value)
				if ds4:GetAsync(player.UserId, Yums.Value) == Yums.Value then
					print("saved")
				end
			end)
		end)
	end)

end)


game.Players.PlayerRemoving:connect(function(player)
	ds1:SetAsync(player.UserId, player.leaderstats.Yums.Value)
	print("saved")
end)

game.Players.PlayerRemoving:Connect(function(player)
	ds2:SetAsync(player.UserId, player.leaderstats.burger.Value)
    print("saved")
end)

game.Players.PlayerRemoving:Connect(function(player)
	ds3:SetAsync(player.UserId, player.leaderstats.Rebirth.Value)
	print("saved")
end)


game.Players.PlayerRemoving:Connect(function(player)
	ds6:SetAsync(player.UserId, player.leaderstats.pets.one.Value)
	print("saved")
end)


game.Players.PlayerRemoving:Connect(function(player)
	ds7:SetAsync(player.UserId, player.leaderstats.pets.two.Value)
	print("saved")
end)


game.Players.PlayerRemoving:Connect(function(player)
	ds8:SetAsync(player.UserId, player.leaderstats.pets.three.Value)
	print("saved")
end)


game.Players.PlayerRemoving:Connect(function(player)
	ds9:SetAsync(player.UserId, player.leaderstats.pets.four.Value)
	print("saved")
end)


game.Players.PlayerRemoving:Connect(function(player)
	ds10:SetAsync(player.UserId, player.leaderstats.pets.five.Value)
	print("saved")
end)

game.Players.PlayerRemoving:Connect(function(player)
	ds11:SetAsync(player.UserId, player.leaderstats.pets.six.Value)
	print("saved")
end)



ATTENTION the API error is not for the whole server but only for some player clients sometimes. It only fails sometimes if someone joins the game and not while someone is playing the game.

1 Like

Thanks, I think this will help. I’m also changing setasync to updateasync btw

my leaderstats is a little messy I guess

I need to use other codes to make it better and saver

What does the API error say?­­­

API request failed but it happens very rarely. idk why btw

You might be hitting the limit for the number of requests that can be sent per minute

yes, that can actually be the problem because it isn’t a problem while playing so then it saves later but if someone joins the game the leaderstats can’t load in because of the other players in the game.