Edit: so I figured it out.
I basically run a function that creates a bunch of buttons. And then for each button it attaches an event. Looks like this:
And it works. But everytime I run the 'recalibrateParties()` I will end up destroying all the buttons. How do I null the event connections? Cause otherwise I think that’s not very efficient, since in theory they will just keep stacking up to null buttons.
Or when you destroy the button in this case, does it disconnect the function?
function onJoin(frame)
print(frame.Name)
end
function recalibrateParties()
local partyCountTotal = workspace:WaitForChild("PartyData"):WaitForChild("PartyCountTotal").Value
local partyList = main:WaitForChild("PartyList"):WaitForChild("ScrollingFrame")
local partyTemplate = partyList:WaitForChild("PartyTemplate")
partyList.Visible = true
backButton.Visible = true
partyList.CanvasSize = UDim2.new(0, 0, partyCountTotal*2, 0)
for i = 1,partyCountTotal do
local newParty = partyTemplate:Clone()
newParty.Parent = partyList
newParty.Position = newParty.Position + UDim2.new(0, 0, 0, (partyCountTotal*200))
newParty.Visible = true
newParty.Name = "Party#"..tostring(partyCountTotal)
newParty:WaitForChild("JoinButton").MouseButton1Down:Connect(onJoin(newParty))
print(newParty.Name)
end
end