Need help with plugin

Hello, I am making a simple plugin that inserts meshes into the workspace. I have a module script that creates a new GUI element and inserts it into the plugin widget. That means when I run this line:`

NewObjectModule.new(scrollingFrame, Cube1ID, "Cube1", OnClick)

It creates a new GUI element like this:
image

The problem relies on the last parameter where I create the new object, the OnClick function that is supposed to run when clicking the “INSERT” button on the GUI. No errors return, but it never runs when I click the button. I will insert the module script under… Any help would be appreciated! Note that I am new to plugins so I am unsure if this will work at all because I’ve tried many different methods but none worked…

Thank you in advance :slight_smile:

Module Script
local InsertService = game:GetService("InsertService")

local module = {}

module.prototype = {}


function module.new(parent, id, objectName, onClick)
	local self = {}
	setmetatable(self, { __index = module.prototype })

	-- Object
	local ObjectFrame = Instance.new("Frame")
	ObjectFrame.BackgroundColor3 = Color3.fromRGB(30,30,30)
	
	
	local ObjectViewPortFrame = Instance.new("ViewportFrame")
	ObjectViewPortFrame.BackgroundTransparency = 1
	ObjectViewPortFrame.Size = UDim2.new(1,0,0.7)
	
	local object = InsertService:LoadAsset(id)
	local part = object:FindFirstChild(objectName)
	object = part
	object.Size = Vector3.new(30,30,30)
	object.Parent = ObjectViewPortFrame
	
	local viewportCamera = Instance.new("Camera")
	viewportCamera.Parent = ObjectViewPortFrame
	viewportCamera.CFrame = CFrame.new(Vector3.new(30,30,30), object.Position)
	ObjectViewPortFrame.CurrentCamera = viewportCamera
	
	local ObjectButton = Instance.new("TextButton")
	ObjectButton.Size = UDim2.new(1,0,0.3,0)
	ObjectButton.Position = UDim2.new(0,0,0.7,0)
	ObjectButton.Text = "INSERT"
	ObjectButton.TextScaled = true
	
	ObjectButton.Parent = ObjectFrame
	ObjectViewPortFrame.Parent = ObjectFrame
	ObjectFrame.Parent = parent
	
	local bindableEvent = Instance.new("BindableEvent")
	bindableEvent.Event:Connect(onClick)
	bindableEvent.Name = "OnButtonClick"
	
	self.ObjectButton = ObjectButton
	self.BindableEvent = bindableEvent
	
	self:Initialize()
	
	
	return self
end

function module.prototype:Initialize()
	self.ObjectButton.MouseButton1Down:Connect(function()
		self.BindableEvent:Fire()
	end)
end

return module