Here’s a modified version of your code to fix this issue:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local Info = script.Parent.Parent.Parent.Information
local Debounce = false
local TweenService = game:GetService("TweenService")
local function TweenUIStrokeColor(uiStroke, targetColor, duration)
local tween = TweenService:Create(uiStroke, TweenInfo.new(duration), {Color = targetColor})
tween:Play()
end
for i, v in pairs(game.ReplicatedStorage.PetFolder:GetChildren()) do
local PetFrame = script.Parent.Parent["Pet Frame"]:Clone()
PetFrame.Parent = script.Parent
local Rarity = v:FindFirstChild("Rarity")
local petName = v.Name
PetFrame.Visible = true
PetFrame.Name = petName
local Module3D = require(game.ReplicatedStorage:WaitForChild("Module3D"))
local Model3D = Module3D:Attach3D(PetFrame, v:Clone())
Model3D:SetDepthMultiplier(1.2)
Model3D.Camera.FieldOfView = 5
Model3D.Visible = true
game:GetService("RunService").RenderStepped:Connect(function()
Model3D:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
end)
PetFrame.InputBegan:Connect(function(input)
if input.UserInputType == Enum.UserInputType.MouseButton1 and not Debounce then
Debounce = true
Info.ItemName.Text = petName
Info.Description.Text = tostring("Rarity: " .. Rarity.Value)
local Pet = game.ReplicatedStorage.PetFolder:FindFirstChild(petName):Clone()
local Model3d = Module3D:Attach3D(Info.ImageContainer.ViewportFrame, Pet)
Model3d:SetDepthMultiplier(1.2)
Model3d.Camera.FieldOfView = 5
Model3d.Visible = true
game:GetService("RunService").RenderStepped:Connect(function()
Model3d:SetCFrame(CFrame.Angles(0, tick() % (math.pi * 2), 0) * CFrame.Angles(math.rad(-10), 0, 0))
end)
if not (PetFrame.UIStroke.Color == Color3.new(0, 0, 0)) then
ReplicatedStorage.Equip:FireServer(petName)
print(petName)
TweenUIStrokeColor(PetFrame.UIStroke, Color3.new(0, 0, 0), 0.5)
else
ReplicatedStorage.Unequip:FireServer(petName)
TweenUIStrokeColor(PetFrame.UIStroke, Color3.new(1, 1, 1), 0.5)
end
wait(0.5) -- you may need to adjust this duration to match your tween time
Debounce = false
end
end)
end
This ^ code adds a Debounce to prevent multiple clicks while the animation is in progress. It ensures that you can’t equip or unequip the pet multiple times, resolving your issue. Adjust the wait duration to match your tween time if necessary.
^ You know you can edit your post and put that there, right?