Leaderstats glitch

The leaderstats doesn’t work/show . Can somebody help?

image



game.Players.PlayerAdded:Connect(function(plr)
	local WPetsFolder = Instance.new("Folder",game.Workspace.Pets)
	WPetsFolder.Name = plr.Name.." Pets"
	
	local leaderstats = Instance.new("Folder",plr)
	leaderstats.Name = "leaderstats"
	



	local Cash = Instance.new("NumberValue",leaderstats)
	Cash.Name = "Cash"
	Cash.Value = 0

	local Clicks = Instance.new("NumberValue",leaderstats)
	Clicks.Name = "Clicks"
	Clicks.Value = 0

	local Rubies = Instance.new("NumberValue",leaderstats)
	Rubies.Name = "Rubies"
	Rubies.Value = 0

	local Values = Instance.new("Folder",plr)
	Values.Name = "Values"

	local Pets = Instance.new("NumberValue",plr)
	Pets.Name = "Pets"
	Pets.Value = 0

	local EquippedPets = Instance.new("NumberValue",plr)
	EquippedPets.Name = "EquippedPets"
	EquippedPets.Value = 0


	local MaxPets = Instance.new("NumberValue",plr)
	MaxPets.Name = "MaxPets"
	MaxPets.Value = 6

	local MaxEquipped = Instance.new("NumberValue",plr)
	MaxEquipped.Name = "MaxEquipped"
	MaxEquipped.Value = 1

	local ClickMultiplier = Instance.new("NumberValue",plr)
	ClickMultiplier.Name = "ClicksMultiplier"
	ClickMultiplier.Value = 1

	local SellMultiplier = Instance.new("NumberValue",plr)
	SellMultiplier.Name = "SellMultiplier"
	SellMultiplier.Value = 1

	local PetsFolder = Instance.new("Folder",Values)
	PetsFolder.Name = "PetsFolder"

	local PetFolder1 = Instance.new("Folder",PetsFolder)
	PetFolder1.Name = "PetFolder1"


	local PetEquipped1 = Instance.new("BoolValue",PetFolder1)
	PetEquipped1.Name = "PetEquipped1"
	PetEquipped1.Value = false

	local PetClick1 = Instance.new("NumberValue",PetFolder1)
	PetClick1.Name = "PetClick1"
	PetClick1.Value = 0

	local PetSell1 = Instance.new("NumberValue",PetFolder1)
	PetSell1.Name = "PetSell1"
	PetSell1.Value = 0

	local PetName1 = Instance.new("StringValue",PetFolder1)
	PetName1.Name = "PetName1"
	PetName1.Value = "N/A"

	local PetEgg1 = Instance.new("StringValue",PetFolder1)
	PetEgg1.Name = "PetEgg1"
	PetEgg1.Value = "N/A"

	local PetFolder2 = Instance.new("Folder",PetsFolder)
	PetFolder2.Name = "PetFolder2"



	local PetEquipped2 = Instance.new("BoolValue",PetFolder2)
	PetEquipped2.Name = "PetEquipped2"
	PetEquipped2.Value = false

	local PetClick2 = Instance.new("NumberValue",PetFolder2)
	PetClick2.Name = "PetClick2"
	PetClick2.Value = 0

	local PetSell2 = Instance.new("NumberValue",PetFolder2)
	PetSell2.Name = "PetSell2"
	PetSell2.Value = 0

	local PetName2 = Instance.new("StringValue",PetFolder2)
	PetName2.Name = "PetName2"
	PetName2.Value = "N/A"

	local PetEgg2 = Instance.new("StringValue",PetFolder2)
	PetEgg2.Name = "PetEgg2"
	PetEgg2.Value = "N/A"


	local PetFolder3 = Instance.new("Folder",PetsFolder)
	PetFolder3.Name = "PetFolder3"


	local PetEquipped3 = Instance.new("BoolValue",PetFolder3)
	PetEquipped3.Name = "PetEquipped3"
	PetEquipped3.Value = false

	local PetClick3 = Instance.new("NumberValue",PetFolder3)
	PetClick3.Name = "PetClick3"
	PetClick3.Value = 0

	local PetSell3 = Instance.new("NumberValue",PetFolder3)
	PetSell3.Name = "PetSell3"
	PetSell3.Value = 0

	local PetName3 = Instance.new("StringValue",PetFolder3)
	PetName3.Name = "PetName3"
	PetName3.Value = "N/A"

	local PetEgg3 = Instance.new("StringValue",PetFolder3)
	PetEgg3.Name = "PetEgg3"
	PetEgg3.Value = "N/A"



	local PetFolder4 = Instance.new("Folder",PetsFolder)
	PetFolder4.Name = "PetFolder4"


	local PetEquipped4 = Instance.new("BoolValue",PetFolder4)
	PetEquipped4.Name = "PetEquipped4"
	PetEquipped4.Value = false

	local PetClick4 = Instance.new("NumberValue",PetFolder4)
	PetClick4.Name = "PetClick4"
	PetClick4.Value = 0

	local PetSell4 = Instance.new("NumberValue",PetFolder4)
	PetSell4.Name = "PetSell4"
	PetSell4.Value = 0

	local PetName4 = Instance.new("StringValue",PetFolder4)
	PetName4.Name = "PetName4"
	PetName4.Value = "N/A"

	local PetEgg4 = Instance.new("StringValue",PetFolder4)
	PetEgg4.Name = "PetEgg4"
	PetEgg4.Value = "N/A"

	local PetFolder5 = Instance.new("Folder",PetsFolder)
	PetFolder5.Name = "PetFolder5"


	local PetEquipped5 = Instance.new("BoolValue",PetFolder5)
	PetEquipped5.Name = "PetEquipped5"
	PetEquipped5.Value = false

	local PetClick5 = Instance.new("NumberValue",PetFolder5)
	PetClick5.Name = "PetClick5"
	PetClick5.Value = 0

	local PetSell5 = Instance.new("NumberValue",PetFolder5)
	PetSell5.Name = "PetSell5"
	PetSell5.Value = 0

	local PetName5 = Instance.new("StringValue",PetFolder5)
	PetName5.Name = "PetName5"
	PetName5.Value = "N/A"

	local PetEgg5 = Instance.new("StringValue",PetFolder5)
	PetEgg5.Name = "PetEgg5"
	PetEgg5.Value = "N/A"

	local PetFolder6 = Instance.new("Folder",PetsFolder)
	PetFolder6.Name = "PetFolder6"


	local PetEquipped6 = Instance.new("BoolValue",PetFolder6)
	PetEquipped6.Name = "PetEquipped6"
	PetEquipped6.Value = false

	local PetClick6 = Instance.new("NumberValue",PetFolder6)
	PetClick6.Name = "PetClick6"
	PetClick6.Value = 0

	local PetSell6 = Instance.new("NumberValue",PetFolder6)
	PetSell6.Name = "PetSell6"
	PetSell6.Value = 0

	local PetName6 = Instance.new("StringValue",PetFolder6)
	PetName6.Name = "PetName6"
	PetName6.Value = "N/A"

	local PetEgg6 = Instance.new("StringValue",PetFolder6)
	PetEgg6.Name = "PetEgg6"
	PetEgg6.Value = "N/A"
	print(plr.Name, plr.UserId)



	local playerUserId = plr.UserId  
	print(playerUserId)

	local data

	data = DS:GetAsync(playerUserId)

	if data then
		Clicks.Value = data.Clicks
		Cash.Value = data.Cash
		Rubies.Value = data.Rubies

		ClickMultiplier.Value = data.ClickMultiplier
		SellMultiplier.Value = data.SellMultiplier

		Pets.Value = data.Pets
		EquippedPets.Value = data.EquippedPets
		MaxPets.Value = data.MaxPets
		MaxEquipped.Value = data.MaxEquipped

		PetEquipped1.Value = data.PetEquipped1
		PetEquipped2.Value = data.PetEquipped2
		PetEquipped3.Value = data.PetEquipped3
		PetEquipped4.Value = data.PetEquipped4
		PetEquipped5.Value = data.PetEquipped5
		PetEquipped6.Value = data.PetEquipped6

		PetClick1.Value = data.PetClick1
		PetClick2.Value = data.PetClick2
		PetClick3.Value = data.PetClick3
		PetClick4.Value = data.PetClick4
		PetClick5.Value = data.PetClick5
		PetClick6.Value = data.PetClick6

		PetSell1.Value = data.PetSell1
		PetSell2.Value = data.PetSell2
		PetSell3.Value = data.PetSell3
		PetSell4.Value = data.PetSell4
		PetSell5.Value = data.PetSell5
		PetSell6.Value = data.PetSell6

		PetName1.Value = data.PetName1
		PetName2.Value = data.PetName2
		PetName3.Value = data.PetName3
		PetName4.Value = data.PetName4
		PetName5.Value = data.PetName5
		PetName6.Value = data.PetName6

		PetEgg1.Value = data.PetEgg1		
		PetEgg2.Value = data.PetEgg2	
		PetEgg3.Value = data.PetEgg3	
		PetEgg4.Value = data.PetEgg4	
		PetEgg5.Value = data.PetEgg5	
		PetEgg6.Value = data.PetEgg6




	end
	print(plr.Name, plr.UserId)
	


	print(data) 
end)


game.Players.PlayerRemoving:Connect(function(plr)
	local playerUserId = plr.UserId  
	print(playerUserId)
	local Values = plr.Values
	local leaderstats = plr.leaderstats
	local PetsFolder = Values.PetsFolder
	local PetFolder1 = PetsFolder.PetFolder1
	local PetFolder2 = PetsFolder.PetFolder2
	local PetFolder3 = PetsFolder.PetFolder3
	local PetFolder4 = PetsFolder.PetFolder4
	local PetFolder5 = PetsFolder.PetFolder5
	local PetFolder6 = PetsFolder.PetFolder6

	local Pets = plr.Pets.Value
	local EquippedPets = plr.EquippedPets.Value
	local MaxPets = plr.MaxPets.Value
	local MaxEquipped = plr.MaxEquipped.Value

	local ClickMultiplier = plr.ClicksMultiplier.Value
	local SellMultiplier = plr.SellMultiplier.Value

	local Clicks = leaderstats.Clicks.Value
	local Cash = leaderstats.Cash.Value
	local Rubies = leaderstats.Rubies.Value

	local PetEquipped1 = PetFolder1.PetEquipped1.Value
	local PetEquipped2 = PetFolder2.PetEquipped2.Value
	local PetEquipped3 = PetFolder3.PetEquipped3.Value
	local PetEquipped4 = PetFolder4.PetEquipped4.Value
	local PetEquipped5 = PetFolder5.PetEquipped5.Value
	local PetEquipped6 = PetFolder6.PetEquipped6.Value

	local PetClick1 = PetFolder1.PetClick1.Value
	local PetClick2 = PetFolder2.PetClick2.Value
	local PetClick3 = PetFolder3.PetClick3.Value
	local PetClick4 = PetFolder4.PetClick4.Value
	local PetClick5 = PetFolder5.PetClick5.Value
	local PetClick6 = PetFolder6.PetClick6.Value

	local PetSell1 = PetFolder1.PetSell1.Value
	local PetSell2 = PetFolder2.PetSell2.Value
	local PetSell3 = PetFolder3.PetSell3.Value
	local PetSell4 = PetFolder4.PetSell4.Value
	local PetSell5 = PetFolder5.PetSell5.Value
	local PetSell6 = PetFolder6.PetSell6.Value


	local PetName1 = PetFolder1.PetName1.Value
	local PetName2 = PetFolder2.PetName2.Value
	local PetName3 = PetFolder3.PetName3.Value
	local PetName4 = PetFolder4.PetName4.Value
	local PetName5 = PetFolder5.PetName5.Value
	local PetName6 = PetFolder6.PetName6.Value


	local PetEgg1 = PetFolder1.PetEgg1.Value
	local PetEgg2 = PetFolder2.PetEgg2.Value
	local PetEgg3 = PetFolder3.PetEgg3.Value
	local PetEgg4 = PetFolder4.PetEgg4.Value
	local PetEgg5 = PetFolder5.PetEgg5.Value
	local PetEgg6 = PetFolder6.PetEgg6.Value


	DS:SetAsync(playerUserId,{
		["Pets"] = Pets;
		["EquippedPets"] = EquippedPets;
		["MaxPets"] = MaxPets;
		["MaxEquipped"] = MaxEquipped;

		["ClickMultiplier"] = ClickMultiplier;
		["SellMultiplier"] = SellMultiplier;

		["Clicks"] = Clicks;
		["Cash"] = Cash;
		["Rubies"] = Rubies;

		["PetEquipped1"] = PetEquipped1;
		["PetEquipped2"] = PetEquipped2;
		["PetEquipped3"] = PetEquipped3;
		["PetEquipped4"] = PetEquipped4;
		["PetEquipped5"] = PetEquipped5;
		["PetEquipped6"] = PetEquipped6;

		["PetClick1"] = PetClick1;
		["PetClick2"] = PetClick2;
		["PetClick3"] = PetClick3;
		["PetClick4"] = PetClick4;
		["PetClick5"] = PetClick5;
		["PetClick6"] = PetClick6;

		["PetSell1"] = PetSell1;
		["PetSell2"] = PetSell2;
		["PetSell3"] = PetSell3;
		["PetSell4"] = PetSell4;
		["PetSell5"] = PetSell5;
		["PetSell6"] = PetSell6;

		["PetName1"] = PetName1;
		["PetName2"] = PetName2;
		["PetName3"] = PetName3;
		["PetName4"] = PetName4;
		["PetName5"] = PetName5;
		["PetName6"] = PetName6;

		["PetEgg1"] = PetEgg1;
		["PetEgg2"] = PetEgg2;
		["PetEgg3"] = PetEgg3;
		["PetEgg4"] = PetEgg4;
		["PetEgg5"] = PetEgg5;
		["PetEgg6"] = PetEgg6;


	})

end)

There are no errors or anything? Also does anything print out? Add a print below the PlayerAdded function so you can check if that’s also working.

1 Like

I read the script a couple times and I agree with @Nakermo
Maybe you need to enable API services

You don’t need to have API enabled to create leaderstats, only when you are about to use Datastores to load some stuff on them, currently he is having issue with the leaderstats not showing up, I’ve tested the code without API enabled and works fine to me, just need KBsnores to clarify on if he gets any errors and if prints are working just fine.

API is enabled but i will print

1 Like

Your data probably does not exist that’s why nothing got added.

So it printed the first print but not the second one

local function PlayerAdded(plr)
print(plr.Name)
local WPetsFolder = Instance.new(“Folder”,game.Workspace.Pets)
WPetsFolder.Name = plr.Name…" Pets"

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

print(plr.Name)

Do you get any errors in the output?

oh im dumb, i forgot to add the “Pets” folder in workspace . I deleted by a mistake earlier

1 Like

now it works
image

I had the same error when I first tested your code, I fixed it and everything worked for me too, check console for errors next time it’s a big help. Good luck with your project.

ok, thank you very much for the help!

1 Like