Advertisement
beati_kay

box select

Mar 22nd, 2025
463
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local ReplicatedStorage = game:GetService("ReplicatedStorage")
  2. local UserInputService = game:GetService("UserInputService")
  3. local RunService = game:GetService("RunService")
  4. local Players = game:GetService("Players")
  5.  
  6. local player = Players.LocalPlayer
  7. local selectTemplate = ReplicatedStorage.select
  8. local selecting = false
  9. local select: Instance, mouseStart: Vector2, mouseEnd: Vector2
  10.  
  11.  
  12. UserInputService.InputBegan:Connect(function(input, processed)
  13.     if processed then return end
  14.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  15.         if not selecting then
  16.             selecting = true
  17.             select = ReplicatedStorage.select:Clone()
  18.             select.Parent = player.PlayerGui.selection
  19.             mouseStart = UserInputService:GetMouseLocation()
  20.             select.Position = UDim2.fromOffset(mouseStart.X, mouseStart.Y)
  21.         end
  22.     end
  23. end)
  24.  
  25. UserInputService.InputEnded:Connect(function(input, processed)
  26.     if input.UserInputType == Enum.UserInputType.MouseButton1 then
  27.         if selecting then
  28.             selecting = false
  29.             select:Destroy()
  30.         end
  31.     end
  32. end)
  33.  
  34. RunService.Heartbeat:Connect(function(dt)
  35.     if selecting then
  36.         mouseEnd = UserInputService:GetMouseLocation()
  37.        
  38.         local x = (mouseStart.X - mouseEnd.X)
  39.         local y = (mouseStart.Y - mouseEnd.Y)
  40.         select.Size = -UDim2.fromOffset(x, y)
  41.     end
  42. end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement