So I am trying to make selection box like this:
But everytime I start holding my leftMouseButton and dragging, the top left corner is always in the left of my screen, not setting onto the position where I began dragging:
I also get no error in the output
My script:
local player = game:GetService("Players").LocalPlayer
local mouse = player:GetMouse()
local userInputService = game:GetService("UserInputService")
local connectionInputBegan = nil
local connectionInputEnded = nil
local userInput = nil
local isActivated = false
local startMousePositionX = nil
local startMousePositionY = nil
local selectionFrame = script.Parent:WaitForChild("Frame")
local function moveMouse()
if isActivated == false then return end
if (Vector2.new(startMousePositionX, startMousePositionY) - Vector2.new(mouse.X,mouse.Y)).Magnitude > 10 then
isMultipleSelecting = true
selectionFrame.Visible = true
selectionFrame.Position = UDim2.new(Vector2.new(startMousePositionX, startMousePositionY))
selectionFrame.Size = UDim2.fromOffset(mouse.X, mouse.Y)
end
end
local function inputEnded(input, processed)
if userInput ~= input then return end
userInput = nil
isActivated = false
connectionInputEnded:Disconnect()
startMousePositionX = nil
startMousePositionY = nil
selectionFrame.Visible = false
print("Deactivated")
end
local function inputBegan(input, processed)
if userInput ~= nil then return end
if processed == true then return end
if input.UserInputType ~= Enum.UserInputType.MouseButton1 then return end
startMousePositionX = mouse.X
startMousePositionY = mouse.Y
userInput = input
isActivated = true
connectionInputEnded = userInputService.InputEnded:Connect(inputEnded)
print("Activated")
end
mouse.Move:Connect(moveMouse)
connectionInputBegan = userInputService.InputBegan:Connect(inputBegan)