Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local UserInputService = game:GetService("UserInputService")
- local RunService = game:GetService("RunService")
- local actionTime = 1 -- Время зажатия в секундах
- local dragThreshold = 5 -- Порог перемещения в пикселях
- local isHolding = false
- local holdStartTime
- local actionPerformed = false
- local initialPosition
- local ScreenGui = Instance.new("ScreenGui")
- ScreenGui.Parent = game.CoreGui
- local button = Instance.new("TextButton")
- button.Size = UDim2.new(0, 200, 0, 50)
- button.Position = UDim2.new(0.5, 0, 0.5, 0)
- button.Text = "Зажми меня"
- button.Parent = ScreenGui
- button.Draggable = true
- button.MouseButton1Down:Connect(function()
- isHolding = true
- holdStartTime = tick()
- actionPerformed = false
- initialPosition = UserInputService:GetMouseLocation()
- end)
- button.MouseButton1Up:Connect(function()
- isHolding = false
- end)
- RunService.RenderStepped:Connect(function()
- if isHolding and not actionPerformed then
- local holdDuration = tick() - holdStartTime
- local currentPosition = UserInputService:GetMouseLocation()
- local distanceMoved = (currentPosition - initialPosition).magnitude
- if distanceMoved > dragThreshold then
- isHolding = false
- return
- end
- if holdDuration >= actionTime then
- actionPerformed = true
- -- Выполнить действие здесь
- print("Кнопка была зажата на 1 секунду!")
- end
- end
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement