Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local Player = game:GetService("Players").LocalPlayer
- local Character
- local UserInputService = game:GetService("UserInputService")
- local VirtualInputManager = game:GetService("VirtualInputManager")
- local lastKeyPress = 0
- local keyPressCooldown = 0.5 -- Cooldown in seconds
- local function isNearMobs(range)
- Character = Player.Character
- if not Character or not Character.HumanoidRootPart then return false end
- for _, folder in ipairs(workspace:GetChildren()) do
- if folder:IsA("Folder") then
- for _, child in ipairs(folder:GetChildren()) do
- if child:FindFirstChild("enemyFolder") then
- for _, npc in ipairs(child.enemyFolder:GetChildren()) do
- if npc:FindFirstChild("HumanoidRootPart") and npc:FindFirstChild("Humanoid") and npc.Humanoid.Health > 0 then
- local distance = (Character.HumanoidRootPart.Position - npc.HumanoidRootPart.Position).Magnitude
- if distance <= range then
- return true
- end
- end
- end
- end
- end
- end
- end
- return false
- end
- local function pressKey(key)
- VirtualInputManager:SendKeyEvent(true, key, false, nil)
- task.wait() -- Very small delay before key release
- VirtualInputManager:SendKeyEvent(false, key, false, nil)
- end
- game:GetService("RunService").Heartbeat:Connect(function()
- if isNearMobs(20) and tick() - lastKeyPress >= keyPressCooldown then
- pressKey("E")
- pressKey("Q")
- lastKeyPress = tick() -- Update the last key press time
- end
- end)
- Player.CharacterAdded:Connect(function(newCharacter)
- Character = newCharacter
- wait(1)
- end)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement