Cat won't stop cloning

Hello everybody, I have a script that detects if a player clicks equip then a cat should duplicate, but the issue is that the cat will not stop cloning. Is there any way that I could edit the script so the cat will duplicate it once? What could I use, I tried to debounce, and comment on your suggestion.

Here is the script
LOCAL SCRIPT

local Equip = script.Parent
local template = script.Parent.Parent.Parent.Parent.Parent


local db = false

Equip.MouseButton1Click:Connect(function()
	Equip.Text = "Equipped"
	if not db  then
		db = true
	end
	local EquippedValue = template:WaitForChild("EquippedValue")
	EquippedValue.Value = "Equipped"

	for _, child in pairs(template:GetChildren()) do 

		if child:IsA("Folder")	then 
			if child.Name == "Cat" then 
				print(child)
				
				if EquippedValue.Value == "Equipped" then 
					
				

				local ReplicatedStorage = game:GetService("ReplicatedStorage")
				local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")
					
				
					EquipPet:FireServer()
					db = false
				else 
					print("Pet is already Equipped")
				end 
				end
			end
		
	end



end)

ServerScript

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")

EquipPet.OnServerEvent:Connect(function(player)
	local Cat = game.ReplicatedStorage.Pets.BasicEggPets.Cat:Clone()
	local char = player.Character or player.CharacterAdded:Wait()
	Cat.Parent = char
end)

You need to check if there is no Cat child inside that template already, if there is, continue to next one, if there is not, then clone and parent it to that template.

1 Like

Easy solution, just check if cat is exists in player’s character or not.
If its not exists then clone the cat.

local ReplicatedStorage = game:GetService("ReplicatedStorage")
local EquipPet = ReplicatedStorage:WaitForChild("EquipPet")

EquipPet.OnServerEvent:Connect(function(player)
    local char = player.Character
    if not char:FindFirstChild("Cat") then -- If character not have cat as their child then
       local Cat = game.ReplicatedStorage.Pets.BasicEggPets.Cat:Clone()
	   Cat.Parent = char
    end
end)
2 Likes