-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAimbot.lua
More file actions
153 lines (120 loc) · 3.68 KB
/
Aimbot.lua
File metadata and controls
153 lines (120 loc) · 3.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
local Aimbot = {}
Aimbot.__index = Aimbot
local RunService = game:GetService("RunService")
local Players = game:GetService("Players")
local localPlr = Players.LocalPlayer
local currentCamera = workspace.CurrentCamera
local function getLocalCharacter()
return localPlr.Character or localPlr.CharacterAdded:Wait()
end
local function getClosestCharacter(characters)
local closest = nil
local shortestDistance = math.huge
local localCharacter = getLocalCharacter()
local success, result = pcall(function()
for _, character in ipairs(characters) do
if character.PrimaryPart and character ~= localCharacter and character.Humanoid.Health > 0 then
local distance = (character.PrimaryPart.Position - localCharacter.PrimaryPart.Position).Magnitude
if distance < shortestDistance then
shortestDistance = distance
closest = character
end
end
end
end)
if not success then warn(result) end
return closest
end
local function getClosestPart(parts)
local origin = getLocalCharacter().PrimaryPart
if not origin then return nil end
local closest = nil
local shortestDistance = math.huge
for _, part in ipairs(parts) do
if part:IsA("BasePart") then
local distance = (part.Position - origin.Position).Magnitude
if distance < shortestDistance then
shortestDistance = distance
closest = part
end
end
end
return closest
end
local function isVisible(part)
local localCharacter = getLocalCharacter()
local origin = localCharacter.PrimaryPart.Position
local direction = (part.Position - origin)
local raycastParams = RaycastParams.new()
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
raycastParams.FilterDescendantsInstances = { part.Parent, localCharacter }
raycastParams.IgnoreWater = true
local result = workspace:Raycast(origin, direction, raycastParams)
return (not result) or result.Instance == part
end
function Aimbot.new()
local self = setmetatable({}, Aimbot)
self.runConnection = nil
self.currentTarget = nil
self.raycastEnabled = false
self.aimboting = false
self.newTargetCallback = nil
local prevTarget = nil
self.runConnection = RunService.RenderStepped:Connect(function()
if self.currentTarget and self.aimboting then
if prevTarget ~= self.currentTarget then
prevTarget = self.currentTarget
if self.newTargetCallback then
self.newTargetCallback(self.currentTarget)
end
end
localPlr.CameraMode = Enum.CameraMode.LockFirstPerson
local part = self.currentTarget
if self.raycastEnabled then
if not isVisible(part) then return end
end
local camPos = currentCamera.CFrame.Position
local targetPos = part.Position
local newLook = (targetPos - camPos).Unit
currentCamera.CFrame = CFrame.new(camPos, camPos + newLook)
end
end)
return self
end
function Aimbot:_onLock()
self.aimboting = true
if self.loopRunConnection then
self.loopRunConnection:Disconnect()
self.loopRunConnection = nil
end
end
function Aimbot:lockOnPart(part)
self:_onLock()
self.currentTarget = part
end
function Aimbot:lockOnCharacters(characters)
self:_onLock()
self.loopRunConnection = RunService.Heartbeat:Connect(function()
local closestCharacter = getClosestCharacter(characters)
if closestCharacter then
self.currentTarget = closestCharacter.PrimaryPart
end
end)
end
function Aimbot:lockOnParts(parts)
self:_onLock()
self.loopRunConnection = RunService.Heartbeat:Connect(function()
local closestPart = getClosestPart(parts)
if closestPart then
self.currentTarget = closestPart
end
end)
end
function Aimbot:stop()
if self.loopRunConnection then
self.loopRunConnection:Disconnect()
end
self.aimboting = false
localPlr.CameraMode = Enum.CameraMode.Classic
end
return Aimbot