I don't know the actual issue; this is my first time I've got this issue and I've been working with MouseButton functions quite alot. I click it for the first time, it functions as if it's being pressed twice and then I click it again, 4 times, again, 8 times and so on.
for i, v in pairs(petsel) do petsel[i].MouseButton1Click:Connect(function() CircleClick(petsel[i], Mouse.X, Mouse.Y) local buttonclick = petsel[i] local PetN = buttonclick.PetN.Text local Opt = script.Parent.Frame.Page.Pets.Opt Opt.PetImage.Image = "rbxassetid://" ..(require(game.ReplicatedStorage.PetDesc).basketdata[PetN][1]).. "" Opt:TweenPosition(UDim2.new(1.1, 0, 0,0), "Out", "Sine", 0.5) Opt.Spawn.MouseButton1Click:connect(function() -- local clicks = 0 -- local clicks = clicks + 1 -- if clicks == 1 then Opt.Spawn.Selectable = false CircleClick(Opt.Spawn, Mouse.X, Mouse.Y) ReplicatedStorage.Events.SpawnPet:FireServer(PetN) Opt:TweenPosition(UDim2.new(0.75, 0, 0,0), "Out", "Sine", 0.5) Opt.Spawn.Selectable = true local clone = Player.PlayerGui.PetUI.Examples.PetSelec.ImageButton:Clone() clone.PetPic.Image = "rbxassetid://".. require(game.ReplicatedStorage.PetDesc).basketdata[PetN][1] .."" clone.ImageColor3 = Color3.new(require(game.ReplicatedStorage.PetDesc).basketdata[PetN][3],require(game.ReplicatedStorage.PetDesc).basketdata[PetN][4],require(game.ReplicatedStorage.PetDesc).basketdata[PetN][5]) clone.PetName.Text = PetN clone.Visible = true clone.Name = PetN print(clone.Name) clone.Parent = Player.PlayerGui.PetUI.SideGUI.SelectionPets local way = Player.PlayerGui.PetUI.SideGUI.SelectionPets:WaitForChild(clone.Name) -- clicks = 0 -- end end) Opt.removep.MouseButton1Click:connect(function() local clicks = 0 local clicks = clicks + 1 if clicks == 1 then Opt.Spawn.Selectable = false Opt.removep.Selectable = false CircleClick(Opt.removep, Mouse.X, Mouse.Y) ReplicatedStorage.Events.RemovePet:FireServer(PetN) Opt:TweenPosition(UDim2.new(0.75, 0, 0,0), "Out", "Sine", 0.5) Opt.Spawn.Selectable = true Opt.removep.Selectable = true local selectionpets = Player:WaitForChild("PlayerGui"):WaitForChild("PetUI"):WaitForChild("SideGUI").SelectionPets if selectionpets:FindFirstChild(PetN) then selectionpets[PetN]:Destroy() end clicks = 0 end end) end) end
The best way to solve this would just to add a debounce. Also, I don't think Opt is defined outside of that mousebutton1click, but correct me if I am wrong.
Opt.Spawn.MouseButton1Click:connect(function()
switch it to
Opt.Spawn.MouseButton1Down:connect(function()