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)