Pet System Help

You can write your topic however you want, but you need to answer these questions:

  1. So im creating an equip and unequip system for my pet system.

  2. The issue is that when I click the frame when the uistroke is black it stops tweening and allows infinite pet equip.

  3. I havent found anything anywhere on this bug.

Here is a video of the bug

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 
	print(petName)
	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 then
			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			
		end
	end)
end
1 Like

Any and all help is appreciated.

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?

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.