Pet Choose not working?

Hi,

I was watching a tutorial on how to make a Pet Hatching System and my script didn’t work when I have the amount of cost. When I changed the operator, >= to <=, it worked but only when I have less than the cost. When I do >= it doesn’t work at all

local cost = 500

local petModule = require(game.ServerScriptService.ModuleScripts:WaitForChild("PetModule"))

script.Parent.ClickDetector.MouseClick:Connect(function(player)

	if player.leaderstats.Diamonds.Value >= cost then
		player.leaderstats.Diamonds.Value = player.leaderstats.Diamonds.Value - cost

		local pet = petModule.chooseRandomPet()
		print(pet.Name.." selected")
	end
	
end)
1 Like

How are you changing the Diamonds value?

If you are editting the values on the client but checking on the server your results would make sense

The module script would be nice but what do i know

I am editing the values on the console, I do game.Players.Remingling.leaderstats.Diamonds.Value = 500

script.Parent.ClickDetector.MouseClick:Connect(function(player)
print(player.leaderstats.Diamonds.Value)
	if player.leaderstats.Diamonds.Value >= cost then
		player.leaderstats.Diamonds.Value = player.leaderstats.Diamonds.Value - cost

		local pet = petModule.chooseRandomPet()
		print(pet.Name.." selected")
	end
	
end)

Try adding a print statement. After setting the value, what does the print say?

2 Likes

That found the problem out, thanks for the debugging but I still don’t know how to fix it.

The problem is, it keeps the same value (0) and when I change it to 500, it still prints the same value I had before I changed it, which is my starting value

Im thinking of doing a heartbeat check

image
The thing you are missing out on is there are two console’s in the studio, one a client-side and the other one serverside. When you use the console right after starting the game, it will use the client-side console. If you want to change the value serverside you should press the button below
image
and it will become
image

2 Likes