Can't get leaderstats IntValue

Hi. I am trying to make a Pet Hatching system and I am running into a little problem. I am trying to get a value from leaderstats and it isn’t getting the value. I tried to look for solutions but I couldn’t really find anything. A snippet of my code is below.

if Player.leaderstats.Strength.Value >= tonumber(Price) then
		Player.leaderstats.Strength.Value -= tonumber(Price)

image

Can you show the us the full code here relating to the system? Could be related to somewhere else

script.Parent.ClickDetector.MouseClick:Connect(function(Player)
	print(PlayersUsing[Player])
	if PlayersUsing[Player]==true then print("Using") return end
	PlayersUsing[Player] = true
	print(tostring(Player))
	print(tonumber(Player:WaitForChild("leaderstats").Strength.Value))
	if Player.leaderstats.Strength.Value >= tonumber(Price) then
		Player.leaderstats.Strength.Value -= tonumber(Price)
		print("yes")
		
		local TableOfPets = {}
		for i, Pet in pairs(PetFolder:GetChildren()) do
			local Rarity = Pet.Rarity.Value
			
			for i = 1, PetRarities.Rarities[Rarity] do
				table.insert(TableOfPets, Pet)
			end
		end
		print("yes")
		local PickedPet = TableOfPets[math.random(1, #TableOfPets)]
		print(tostring(PickedPet))
		local clone = PickedPet:Clone()
		local HatchingGui = Player.PlayerGui.PetHatching
		local Egg = HatchingGui:FindFirstChild("Frame"):FindFirstChild("Egg")
		Egg.Visible=true
		
		local Tick = tick()
		local Timer = 3
		
		while tick() - Tick<Timer do
			Egg.Rotation = 8
			wait(.05)
			Egg.Rotation = 0
			wait(.05)
			Egg.Rotation = -8
			wait(.05)
			Egg.Rotation = 0
			wait(.05)
		end
		Egg.Visible=false
		local Pet = HatchingGui:FindFirstChild("Frame").PetImages:FindFirstChild(PickedPet.Name)
		Pet.Visible = true
		wait(3)
		Pet.Visible=false
		PlayersUsing[Player] = false
	else
		PlayersUsing[Player] = false
		print(PlayersUsing[Player])
		print("not enough money")
	end
end)

the print(“yes”) is for testing.

Okay doesn’t seem to be anything wrong, maybe it’s the way you’re increasing the strength value? Are you increasing it locally?

Yeah. Should I change it to a script instead of a Local Script?

If the code reading the strength value is a regular script then yes you do need to convert how you’re increasing the strength value to be on the server, though if you use anything UserInputService related, you’ll need to use RemoteEvents to tell the server to update the value

1 Like

It worked. Instead of changing the value locally I used a remote event. Thanks for your help.

Can you mark the post as a solution

This person helped, so you might as well

I marked it as a solution. If it isn’t please let me know.

1 Like