-- Module script ------
function UIClickDetection.OnButtonClick(button, functionToDo)
button.MouseButton1Click:Connect(functionToDo)
end
-- Server script ------
local function DoSomething(button)
print(button.Name)
end
UIClickDetection.OnButtonClick(someButton, DoSomething)
I am a bit confused on what I should do, when I am calling the module’s function for the second parameter how do I pass the function?
UIClickDetectionModule.OnButtonClick(quickBuildMainGuiClonePositiveButton, functionToDo())
-- Do I need to pass the parameter where I am calling the module function?
-- QuickBuild
local QuickBuild = script.Parent
-- Modules Folders
local ObjectModules = script.Object
local ObjectPositioningModules = ObjectModules.Positioning
local UIModules = script.UI
-- Modules
-- ObjectPositioning
local PositionObjectModule = require(ObjectPositioningModules.PositionObject)
-- UI
local UIClickDetectionModule = require(UIModules.UIClickDetection)
local MainPluginUiModule = require(UIModules.MainPluginUI)
-- Services
local ChangeHistoryService = game:GetService("ChangeHistoryService")
local Selection = game:GetService("Selection")
-- Create a new toolbar section titled "Custom Script Tools"
local toolbar = plugin:CreateToolbar("Quick Build")
-- Add a toolbar button named "Create Empty Script"
local quickBuildButton = toolbar:CreateButton("Open QuickBuild UI", "Open the QuickBuild UI", "rbxassetid://4458901886")
-- Make button clickable even if 3D viewport is hidden
quickBuildButton.ClickableWhenViewportHidden = false
-- Tables
local newSelection = {}
-- Debounces
local Opened = false
-- Create new "DockWidgetPluginGuiInfo" object
local quickBuildWidgetInfo = DockWidgetPluginGuiInfo.new(
Enum.InitialDockState.Left,
false, -- Widget will be initially enabled
false, -- Don't override the previous enabled state
200, -- Default width of the floating window
300, -- Default height of the floating window
150, -- Minimum width of the floating window (optional)
150 -- Minimum height of the floating window (optional)
)
MainPluginUiModule:createMainPluginUI(quickBuildWidgetInfo, "Quick Build")
local QuickBuildWidget = MainPluginUiModule:GetMainPluginUI()
local QuickBuildMainGui = QuickBuild.QuickBuildMainGui
QuickBuildMainGui.Parent = QuickBuildWidget
local quickBuildMainGuiClonePositiveButton = QuickBuildMainGui.ClonePositive
local quickBuildMainGuiCloneNegativeButton = QuickBuildMainGui.CloneNegative
-- Open/Close GUI
quickBuildButton.Click:Connect(function()
if Opened then
QuickBuildWidget.Enabled = false
Opened = false
else
QuickBuildWidget.Enabled = true
Opened = true
end
end)
local function onPositionButtonClicked(button)
local selectedObject = Selection:Get()
--local parent = game:GetService("ServerScriptService")
if #selectedObject == 1 then
if selectedObject and #selectedObject == 1 and selectedObject[1] ~= nil and selectedObject[1]:IsA("Part") then
local objectToClone = selectedObject[1]:Clone()
PositionObjectModule:PositionObject(objectToClone, "Positive")
-- Set selection to object cloned for efficiency
table.insert(newSelection, objectToClone)
Selection:Set(newSelection)
-- Remove from table so multiple objects don't get selected
table.remove(newSelection, 1)
ChangeHistoryService:SetWaypoint("Positioned the selected object")
end
elseif #selectedObject > 1 then
warn("Cannot select more than one object")
elseif #selectedObject < 1 then
warn("Select at least one object")
end
end
UIClickDetectionModule.OnButtonClick(quickBuildMainGuiClonePositiveButton, onPositionButtonClicked())
Here is my module script code:
-- QuickBuild
local QuickBuild = script.Parent.Parent.Parent
-- Modules
local MainPluginUiModule = require(QuickBuild.Main.UI.MainPluginUI)
local PositionObjectModule = require(QuickBuild.Main.Object.Positioning.PositionObject)
-- Main Plugin UI
local QuickBuildWidget = MainPluginUiModule:GetMainPluginUI()
-- Module code
local UIClickDetection = {}
function UIClickDetection.OnButtonClick(button, functionToDo)
button.MouseButton1Click:Connect(function()
functionToDo(button)
end)
end
-- End of Modules
------------------
-- Return module calls
return UIClickDetection