From a94aee800f3b0f2480471bdfcda467b4d70f5f9a Mon Sep 17 00:00:00 2001 From: sindri <33976067+isarsindri@users.noreply.github.com> Date: Mon, 2 Mar 2026 14:22:34 +0100 Subject: [PATCH] Enhance draggable module with environment checks Updated UserInputService initialization and added checks for non-Roblox environments and GuiObject types. --- src/draggable.luau | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/draggable.luau b/src/draggable.luau index 2556301..a0a58ef 100644 --- a/src/draggable.luau +++ b/src/draggable.luau @@ -1,11 +1,23 @@ -local UserInputService = game:GetService("UserInputService") or nil +local UserInputService = game and game:GetService("UserInputService") or nil +-- Factory: inject Vide functions to avoid cyclic requires return function(action, cleanup) return function(opts) opts = opts or {} local axis = opts.axis or "both" -- "x" | "y" | "both" return action(function(gui) + -- Non-Roblox / unit-test environment: allow requiring this module without crashing. + -- Draggable behaviour is disabled when UserInputService is unavailable. + if not UserInputService then + return + end + + -- Optional hardening: ignore non-GuiObject targets + if typeof(gui) ~= "Instance" or not gui:IsA("GuiObject") then + return + end + local dragging = false local dragInput local dragStart @@ -46,6 +58,7 @@ return function(action, cleanup) if input.UserInputState == Enum.UserInputState.End then dragging = false if changedConn then changedConn:Disconnect() end + if opts.onDragEnd then opts.onDragEnd(gui.Position) end