How would just delete the variable if the thing I'm trying to assign it to doesnt exist

Basically I have a script that clones a button, but the amount of times it clones it varies, so I need to make a variable for the ones that have been cloned, but don’t want an error to appear if for example, only 6 buttons were cloned, so the other 14 variables won’t work.

local button1 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton1
					local button2 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton2
					local button3 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton3
					local button4 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton4
					local button5 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton5
					local button6 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton6
					local button7 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton7
					local button8 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton8
					local button9 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton9
					local button10 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton10
					local button11 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton11
					local button12 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton12
					local button13 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton13
					local button14 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton14
					local button15 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton15
					local button16 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton16
					local button17 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton17
					local button18 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton18
					local button19 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton19
					local button20 = loser.PlayerGui.Donation.Frame.itemsScroller.DonateButton20

use

pcall(function()
  -- code for each button
end)

for each button individually

1 Like

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