The problem lies in the logic of your code. You repeat a while loop, causing the MouseButton1Click event to establish itself multiple times. Thats why when you click it even once, the MouseButton1Click event runs multiple times, probably causing the yielding issue.
Try simplifying your code a little bit.
script.Parent.Template.EquipButton.MouseButton1Click:Connect(function()
-- rest of code
end)
This also leads me to assume that you don’t clone the models using pet:Clone() in your setViewport function, but directly parent them, causing them to disappear from the folder.
Do you suspect anything that could cause something like this?
Well that would work, but it’d be very hard to automatically track multiple templates that represent multiple pets, especially when games have millions of unique players.
Hard to explain. Basically, players will have a unique amount of pets, and I don’t know how to adjust the amount of MouseButton1Click events to the amount of pets that player has.
(aka. I want to automatically apply the mouse event to all templates, not just one.