Advertisement
aesnike

key-abiltiy

Oct 26th, 2024 (edited)
39
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. local Player = game:GetService("Players").LocalPlayer
  2. local Character
  3. local UserInputService = game:GetService("UserInputService")
  4. local VirtualInputManager = game:GetService("VirtualInputManager")
  5.  
  6. local lastKeyPress = 0
  7. local keyPressCooldown = 0.5 -- Cooldown in seconds
  8.  
  9.  
  10. local function isNearMobs(range)
  11. Character = Player.Character
  12. if not Character or not Character.HumanoidRootPart then return false end
  13.  
  14. for _, folder in ipairs(workspace:GetChildren()) do
  15. if folder:IsA("Folder") then
  16. for _, child in ipairs(folder:GetChildren()) do
  17. if child:FindFirstChild("enemyFolder") then
  18. for _, npc in ipairs(child.enemyFolder:GetChildren()) do
  19. if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
  20. local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
  21. if distance <= range then
  22. return true
  23. end
  24. end
  25. end
  26. end
  27. end
  28. end
  29. end
  30. return false
  31. end
  32.  
  33.  
  34. local function pressKey(key)
  35. VirtualInputManager:SendKeyEvent(true, key, false, nil)
  36. task.wait() -- Very small delay before key release
  37. VirtualInputManager:SendKeyEvent(false, key, false, nil)
  38. end
  39.  
  40.  
  41. game:GetService("RunService").Heartbeat:Connect(function()
  42. if isNearMobs(20) and tick() - lastKeyPress >= keyPressCooldown then
  43. pressKey("E")
  44. pressKey("Q")
  45. lastKeyPress = tick() -- Update the last key press time
  46. end
  47. end)
  48.  
  49.  
  50. Player.CharacterAdded:Connect(function(newCharacter)
  51. Character = newCharacter
  52. wait(1)
  53. end)
  54.  
  55.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement