Scripting Issues about Pet System. (PLEASE HELP!)

  1. What do you want to achieve? A working auto hatch for pet system.

  2. What is the issue? The Stop Auto Hatching button won’t hide when the player does not have enough money.

  3. What solutions have you tried so far? This Pet System is from Polarisprog series. Doesn’t talk about the solution to this in his videos.

Script 1: (when T button on GUI is pressed, local script)

Tbtn.MouseButton1Click:Connect(function()
		if player.Character ~= nil and isHatching == false then
			local nearestEgg
			local plrPos = player.Character.HumanoidRootPart.Position

			for i, v in pairs(Eggs:GetChildren()) do
				if nearestEgg == nil  then
					nearestEgg = v
				else
					if (plrPos - v.PrimaryPart.Position).Magnitude < (nearestEgg.PrimaryPart.Position - plrPos).Magnitude then
						nearestEgg = v
					end
				end
			end

			if player:DistanceFromCharacter(nearestEgg.EggMesh.PrimaryPart.Position) < MaxDisplayDistance  then
				canHatch = true
			else
				canHatch = false
			end


			if canHatch == true then
				IsAutoHatching = true
				while IsAutoHatching == true do
					local result = replicatedStorage:WaitForChild("EggHatchingRemotes"):WaitForChild("AutoHatch"):InvokeServer(nearestEgg)
					if result ~= "Cannot Hatch" and result ~= "The player does not own the gamepass!" then
						if not cooldown then
							stopAutoHatching.Visible = true

							cooldown = true
							hatchOne(result,nearestEgg)	
							wait(.1)
							cooldown = false
						end
					elseif result == "The player does not own the gamepass!" then
						mps:PromptGamePassPurchase(player, autoHatchID)
					end
					if IsAutoHatching == false then
						break
					end
				end
			end
		end
	end)

stopAutoHatching.MouseButton1Click:Connect(function()
	IsAutoHatching = false
	stopAutoHatching.Visible = false
end)

Script 2: (chooses pets, checks money etc. , server script)

game.ReplicatedStorage.EggHatchingRemotes.AutoHatch.OnServerInvoke = function(player, egg)
	if player.Values.CanAutoHatch.Value == true then
		local eggModel = workspace.Eggs:FindFirstChild(egg.Name)
		if eggModel ~= nil then
			local price = eggModel.Price.Value
			local currency = eggModel.Currency.Value
			local numberPrice = tonumber(price)


			if tonumber(player.leaderstats[currency].Value) >= price then
				player.leaderstats[currency].Value = player.leaderstats[currency].Value - price
				local chosenPet = choosePet(egg)
				local val = Instance.new("StringValue")
				val.Name = chosenPet
				val.Parent = player.Pets

				return chosenPet
			else
				return "Cannot Hatch"
			end
		end
	else
		return "The player does not own the gamepass!"
	end	
end

All help is appreciated. All variabled are defined by the way.
Regards,
Flash :slight_smile:

1 Like

The DevForum is used for help. And no one is helping. What is the point of being a Roblox dev on this dumb Roblox platform.

In your first snippet, you are only calling this code when the button is pressed. Setup a listener for your player’s money and track its change. When it changes, update the buttons visibility accordingly.

1 Like