I have this client-side code, it fires the function more than once when the “yes” button is clicked here is the full code:
game.ReplicatedStorage.Eggs.EggAreYouSure.OnClientEvent:Connect(function(egg, prox, cost, pet)
local debounce = false
local plr = game.Players.LocalPlayer
print(egg)
print(prox)
print(cost)
print("For loop started")
print(prox.Parent.Parent)
if script.Parent.Visible == false and debounce == false then
script.Parent.Visible = true
script.Parent.Frame.TextLabel.Text = tostring("Are you sure you want to buy ".. egg.Name .. " for "..cost.." Gold?")
script.Parent.Frame.Yes.TextButton.MouseButton1Click:Connect(function()
if plr.leaderstats.Gold.Value >= cost then
print(pet)
local newPet = game.ReplicatedStorage.SingularPet:Clone()
newPet.Parent = plr.PlayerGui.InventoryGui.PetsUI.PetsFront.ScrollingFrame
local modelPet = game.ReplicatedStorage.AllItems.AllPets:FindFirstChild(pet)
if modelPet then
newPet.ImageButton.Image = modelPet.Id.Value
end
game.ReplicatedStorage.Eggs.EggAreYouSure:FireServer(cost)
--Sounds
sound:PlayLocalSound(script.Ching)
sound:PlayLocalSound(script.Click)
script.Parent.Visible = false
debounce = true
local egg = script.Parent.Parent.Parent.Egg.ImageLabel
print("Bought")
egg.Visible = true
--Tweens
egg:TweenSize(UDim2.new(0.7, 0, 0.7, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.5)
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Rotation = 20}):Play()
sound:PlayLocalSound(script.EggCrack)
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Rotation = 0}):Play()
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Rotation = -30}):Play()
sound:PlayLocalSound(script.EggCrack)
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Rotation = 0}):Play()
egg:TweenSize(UDim2.new(0.1, 0, 0.1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.5)
task.wait(0.5)
egg.Visible = false
else
script.Parent.Visible = false
end
end)
script.Parent.Frame.No.TextButton.MouseButton1Click:Connect(function()
script.Parent.Visible = false
sound:PlayLocalSound(script.Click)
end)
end
end)
here is the part that i think has the problem
script.Parent.Frame.Yes.TextButton.MouseButton1Click:Connect(function()
if plr.leaderstats.Gold.Value >= cost then
print(pet)
local newPet = game.ReplicatedStorage.SingularPet:Clone()
newPet.Parent = plr.PlayerGui.InventoryGui.PetsUI.PetsFront.ScrollingFrame
local modelPet = game.ReplicatedStorage.AllItems.AllPets:FindFirstChild(pet)
if modelPet then
newPet.ImageButton.Image = modelPet.Id.Value
end
game.ReplicatedStorage.Eggs.EggAreYouSure:FireServer(cost)
--Sounds
sound:PlayLocalSound(script.Ching)
sound:PlayLocalSound(script.Click)
script.Parent.Visible = false
debounce = true
local egg = script.Parent.Parent.Parent.Egg.ImageLabel
print("Bought")
egg.Visible = true
--Tweens
egg:TweenSize(UDim2.new(0.7, 0, 0.7, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.5)
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Rotation = 20}):Play()
sound:PlayLocalSound(script.EggCrack)
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Rotation = 0}):Play()
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Bounce, Enum.EasingDirection.Out), {Rotation = -30}):Play()
sound:PlayLocalSound(script.EggCrack)
task.wait(0.5)
tween:Create(egg, TweenInfo.new(0.5, Enum.EasingStyle.Linear, Enum.EasingDirection.In), {Rotation = 0}):Play()
egg:TweenSize(UDim2.new(0.1, 0, 0.1, 0), Enum.EasingDirection.In, Enum.EasingStyle.Quad, 0.5)
task.wait(0.5)
egg.Visible = false
else
script.Parent.Visible = false
end
end)