Advertisement
ERROR_CODE

ButtonHold

Oct 20th, 2024 (edited)
50
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.55 KB | None | 0 0
  1. local UserInputService = game:GetService("UserInputService")
  2. local RunService = game:GetService("RunService")
  3. local actionTime = 1 -- Время зажатия в секундах
  4. local dragThreshold = 5 -- Порог перемещения в пикселях
  5.  
  6. local isHolding = false
  7. local holdStartTime
  8. local actionPerformed = false
  9. local initialPosition
  10.  
  11. local ScreenGui = Instance.new("ScreenGui")
  12. ScreenGui.Parent = game.CoreGui
  13. local button = Instance.new("TextButton")
  14. button.Size = UDim2.new(0, 200, 0, 50)
  15. button.Position = UDim2.new(0.5, 0, 0.5, 0)
  16. button.Text = "Зажми меня"
  17. button.Parent = ScreenGui
  18. button.Draggable = true
  19.  
  20. button.MouseButton1Down:Connect(function()
  21.     isHolding = true
  22.     holdStartTime = tick()
  23.     actionPerformed = false
  24.     initialPosition = UserInputService:GetMouseLocation()
  25. end)
  26.  
  27. button.MouseButton1Up:Connect(function()
  28.     isHolding = false
  29. end)
  30.  
  31. RunService.RenderStepped:Connect(function()
  32.     if isHolding and not actionPerformed then
  33.         local holdDuration = tick() - holdStartTime
  34.         local currentPosition = UserInputService:GetMouseLocation()
  35.         local distanceMoved = (currentPosition - initialPosition).magnitude
  36.  
  37.         if distanceMoved > dragThreshold then
  38.             isHolding = false
  39.             return
  40.         end
  41.  
  42.         if holdDuration >= actionTime then
  43.             actionPerformed = true
  44.             -- Выполнить действие здесь
  45.             print("Кнопка была зажата на 1 секунду!")
  46.         end
  47.     end
  48. end)
  49.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement