Hello there, I’ve been trying to find a way to disonnect the connection in this function below and I cant figure out how. Is it necessary to do that here? Any ideas how? Should I just have a button inside the template instead with a script inside it(although I appreciate the tidy look of having one script)?
Context: the below function is used to create buttons inside a scrolling frame that the player can click to buy items from. Template is just an image inside the script with a Text Label inside it.
local function addToFrame(item, parent)
local scrollingFrame = script.Parent:WaitForChild(parent):WaitForChild("ScrollingFrame")
local newTemplate = template:Clone()
newTemplate.Name = item.Name
newTemplate.ItemName.Text = item.Name
newTemplate.Parent = scrollingFrame
buttonconnections[#buttonconnections+1] = newTemplate.MouseButton1Click:Connect(function()
local success = false
success = game.ReplicatedStorage.CheckSale:InvokeServer(item.Name)
if success then
newTemplate:Destroy()
end
end)
end
Thanks for your time!!!