View difference between Paste ID: htqeCcXy and fKyW0Wfx
SHOW: | | - or go back to the newest paste.
1
if getgenv().Aiming then return getgenv().Aiming end
2
3
-- // Services
4
local Players = game:GetService("Players")
5
local Workspace = game:GetService("Workspace")
6
local GuiService = game:GetService("GuiService")
7
local RunService = game:GetService("RunService")
8
9
-- // Vars
10
local Heartbeat = RunService.Heartbeat
11
local LocalPlayer = Players.LocalPlayer
12
local CurrentCamera = Workspace.CurrentCamera
13
local Mouse = LocalPlayer:GetMouse()
14
15
-- // Optimisation Vars (ugly)
16
local Drawingnew = Drawing.new
17
local Color3fromRGB = Color3.fromRGB
18
local Vector2new = Vector2.new
19
local GetGuiInset = GuiService.GetGuiInset
20
local Randomnew = Random.new
21
local mathfloor = math.floor
22
local CharacterAdded = LocalPlayer.CharacterAdded
23
local CharacterAddedWait = CharacterAdded.Wait
24
local WorldToViewportPoint = CurrentCamera.WorldToViewportPoint
25
local RaycastParamsnew = RaycastParams.new
26
local EnumRaycastFilterTypeBlacklist = Enum.RaycastFilterType.Blacklist
27
local Raycast = Workspace.Raycast
28
local GetPlayers = Players.GetPlayers
29
local Instancenew = Instance.new
30
local IsDescendantOf = Instancenew("Part").IsDescendantOf
31
local FindFirstChildWhichIsA = Instancenew("Part").FindFirstChildWhichIsA
32
local FindFirstChild = Instancenew("Part").FindFirstChild
33
local tableremove = table.remove
34
local tableinsert = table.insert
35
36
-- // Silent Aim Vars
37
getgenv().Aiming = {
38
    Enabled = true,
39
40
    ShowFOV = false,
41-
    FOV = 35,
41+
    FOV = 15,
42
    FOVSides = 12,
43
    FOVColour = Color3fromRGB(231, 84, 128),
44
45
    VisibleCheck = true,
46
    
47
    HitChance = 100,
48
49
    Selected = nil,
50
    SelectedPart = nil,
51
52
    TargetPart = {"HumanoidRootPart"},
53
54
    Ignored = {
55
        Teams = {
56
            {
57
                Team = LocalPlayer.Team,
58
                TeamColor = LocalPlayer.TeamColor,
59
            },
60
        },
61
        Players = {
62
            LocalPlayer,
63
            91318356
64
        }
65
    }
66
}
67
local Aiming = getgenv().Aiming
68
69
-- // Create circle
70
local circle = Drawingnew("Circle")
71
circle.Transparency = 1
72
circle.Thickness = 2
73
circle.Color = Aiming.FOVColour
74
circle.Filled = false
75
Aiming.FOVCircle = circle
76
77
-- // Update
78
function Aiming.UpdateFOV()
79
    -- // Make sure the circle exists
80
    if not (circle) then
81
        return
82
    end
83
84
    -- // Set Circle Properties
85
    circle.Visible = Aiming.ShowFOV
86
    circle.Radius = (Aiming.FOV * 3)
87
    circle.Position = Vector2new(Mouse.X, Mouse.Y + GetGuiInset(GuiService).Y)
88
    circle.NumSides = Aiming.FOVSides
89
    circle.Color = Aiming.FOVColour
90
91
    -- // Return circle
92
    return circle
93
end
94
95
-- // Custom Functions
96
local CalcChance = function(percentage)
97
    -- // Floor the percentage
98
    percentage = mathfloor(percentage)
99
100
    -- // Get the chance
101
    local chance = mathfloor(Randomnew().NextNumber(Randomnew(), 0, 1) * 100) / 100
102
103
    -- // Return
104
    return chance <= percentage / 100
105
end
106
107
-- // Customisable Checking Functions: Is a part visible
108
function Aiming.IsPartVisible(Part, PartDescendant)
109
    -- // Vars
110
    local Character = LocalPlayer.Character or CharacterAddedWait(CharacterAdded)
111
    local Origin = CurrentCamera.CFrame.Position
112
    local _, OnScreen = WorldToViewportPoint(CurrentCamera, Part.Position)
113
114
    -- //
115
    if (OnScreen) then
116
        -- // Vars
117
        local raycastParams = RaycastParamsnew()
118
        raycastParams.FilterType = EnumRaycastFilterTypeBlacklist
119
        raycastParams.FilterDescendantsInstances = {Character, CurrentCamera}
120
121
        -- // Cast ray
122
        local Result = Raycast(Workspace, Origin, Part.Position - Origin, raycastParams)
123
124
        -- // Make sure we get a result
125
        if (Result) then
126
            -- // Vars
127
            local PartHit = Result.Instance
128
            local Visible = (not PartHit or IsDescendantOf(PartHit, PartDescendant))
129
130
            -- // Return
131
            return Visible
132
        end
133
    end
134
135
    -- // Return
136
    return false
137
end
138
139
-- // Ignore player
140
function Aiming.IgnorePlayer(Player)
141
    -- // Vars
142
    local Ignored = Aiming.Ignored
143
    local IgnoredPlayers = Ignored.Players
144
145
    -- // Find player in table
146
    for _, IgnoredPlayer in ipairs(IgnoredPlayers) do
147
        -- // Make sure player matches
148
        if (IgnoredPlayer == Player) then
149
            return false
150
        end
151
    end
152
153
    -- // Blacklist player
154
    tableinsert(IgnoredPlayers, Player)
155
    return true
156
end
157
158
-- // Unignore Player
159
function Aiming.UnIgnorePlayer(Player)
160
    -- // Vars
161
    local Ignored = Aiming.Ignored
162
    local IgnoredPlayers = Ignored.Players
163
164
    -- // Find player in table
165
    for i, IgnoredPlayer in ipairs(IgnoredPlayers) do
166
        -- // Make sure player matches
167
        if (IgnoredPlayer == Player) then
168
            -- // Remove from ignored
169
            tableremove(IgnoredPlayers, i)
170
            return true
171
        end
172
    end
173
174
    -- //
175
    return false
176
end
177
178
-- // Ignore team
179
function Aiming.IgnoreTeam(Team, TeamColor)
180
    -- // Vars
181
    local Ignored = Aiming.Ignored
182
    local IgnoredTeams = Ignored.Teams
183
184
    -- // Find team in table
185
    for _, IgnoredTeam in ipairs(IgnoredTeams) do
186
        -- // Make sure team matches
187
        if (IgnoredTeam.Team == Team and IgnoredTeam.TeamColor == TeamColor) then
188
            return false
189
        end
190
    end
191
192
    -- // Ignore team
193
    tableinsert(IgnoredTeams, {Team, TeamColor})
194
    return true
195
end
196
197
-- // Unignore team
198
function Aiming.UnIgnoreTeam(Team, TeamColor)
199
    -- // Vars
200
    local Ignored = Aiming.Ignored
201
    local IgnoredTeams = Ignored.Teams
202
203
    -- // Find team in table
204
    for i, IgnoredTeam in ipairs(IgnoredTeams) do
205
        -- // Make sure team matches
206
        if (IgnoredTeam.Team == Team and IgnoredTeam.TeamColor == TeamColor) then
207
            -- // Remove
208
            tableremove(IgnoredTeams, i)
209
            return true
210
        end
211
    end
212
213
    -- // Return
214
    return false
215
end
216
217
-- //  Toggle team check
218
function Aiming.TeamCheck(Toggle)
219
    if (Toggle) then
220
        return Aiming.IgnoreTeam(LocalPlayer.Team, LocalPlayer.TeamColor)
221
    end
222
223
    return Aiming.UnIgnoreTeam(LocalPlayer.Team, LocalPlayer.TeamColor)
224
end
225
226
-- // Check teams
227
function Aiming.IsIgnoredTeam(Player)
228
    -- // Vars
229
    local Ignored = Aiming.Ignored
230
    local IgnoredTeams = Ignored.Teams
231
232
    -- // Check if team is ignored
233
    for _, IgnoredTeam in ipairs(IgnoredTeams) do
234
        -- // Make sure team matches
235
        if (Player.Team == IgnoredTeam.Team and Player.TeamColor == IgnoredTeam.TeamColor) then
236
            return true
237
        end
238
    end
239
240
    -- // Return
241
    return false
242
end
243
244
-- // Check if player (and team) is ignored
245
function Aiming.IsIgnored(Player)
246
    -- // Vars
247
    local Ignored = Aiming.Ignored
248
    local IgnoredPlayers = Ignored.Players
249
250
    -- // Loop
251
    for _, IgnoredPlayer in ipairs(IgnoredPlayers) do
252
        -- // Check if Player Id
253
        if (typeof(IgnoredPlayer) == "number" and Player.UserId == IgnoredPlayer) then
254
            return true
255
        end
256
257
        -- // Normal Player Instance
258
        if (IgnoredPlayer == Player) then
259
            return true
260
        end
261
    end
262
263
    -- // Team check
264
    return Aiming.IsIgnoredTeam(Player)
265
end
266
267
-- // Get the Direction, Normal and Material
268
function Aiming.Raycast(Origin, Destination, UnitMultiplier)
269
    if (typeof(Origin) == "Vector3" and typeof(Destination) == "Vector3") then
270
        -- // Handling
271
        if (not UnitMultiplier) then UnitMultiplier = 1 end
272
273
        -- // Vars
274
        local Direction = (Destination - Origin).Unit * UnitMultiplier
275
        local Result = Raycast(Workspace, Origin, Direction)
276
277
        -- // Make sure we have a result
278
        if (Result) then
279
            local Normal = Result.Normal
280
            local Material = Result.Material
281
282
            return Direction, Normal, Material
283
        end
284
    end
285
286
    -- // Return
287
    return nil
288
end
289
290
-- // Get Character
291
function Aiming.Character(Player)
292
    return Player.Character
293
end
294
295
-- // Check Health
296
function Aiming.CheckHealth(Player)
297
    -- // Get Humanoid
298
    local Character = Aiming.Character(Player)
299
    local Humanoid = FindFirstChildWhichIsA(Character, "Humanoid")
300
301
    -- // Get Health
302
    local Health = (Humanoid and Humanoid.Health or 0)
303
304
    -- //
305
    return Health > 0
306
end
307
308
-- // Check if silent aim can used
309
function Aiming.Check()
310
    return (Aiming.Enabled == true and Aiming.Selected ~= LocalPlayer and Aiming.SelectedPart ~= nil)
311
end
312
Aiming.checkSilentAim = Aiming.Check
313
314
-- // Get Closest Target Part
315
function Aiming.GetClosestTargetPartToCursor(Character)
316
    local TargetParts = Aiming.TargetPart
317
318
    -- // Vars
319
    local ClosestPart = nil
320
    local ClosestPartPosition = nil
321
    local ClosestPartOnScreen = false
322
    local ClosestPartMagnitudeFromMouse = nil
323
    local ShortestDistance = 1/0
324
325
    -- //
326
    local function CheckTargetPart(TargetPart)
327
        -- // Convert string -> Instance
328
        if (typeof(TargetPart) == "string") then
329
            TargetPart = FindFirstChild(Character, TargetPart)
330
        end
331
332
        -- // Make sure we have a target
333
        if not (TargetPart) then
334
            return
335
        end
336
337
        -- // Get the length between Mouse and Target Part (on screen)
338
        local PartPos, onScreen = WorldToViewportPoint(CurrentCamera, TargetPart.Position)
339
        local GuiInset = GetGuiInset(GuiService)
340
        local Magnitude = (Vector2new(PartPos.X, PartPos.Y - GuiInset.Y) - Vector2new(Mouse.X, Mouse.Y)).Magnitude
341
342
        -- //
343
        if (Magnitude < ShortestDistance) then
344
            ClosestPart = TargetPart
345
            ClosestPartPosition = PartPos
346
            ClosestPartOnScreen = onScreen
347
            ClosestPartMagnitudeFromMouse = Magnitude
348
            ShortestDistance = Magnitude
349
        end
350
    end
351
352
    -- // String check
353
    if (typeof(TargetParts) == "string") then
354
        -- // Check if it all
355
        if (TargetParts == "All") then
356
            -- // Loop through character children
357
            for _, v in ipairs(Character:GetChildren()) do
358
                -- // See if it a part
359
                if not (v:IsA("BasePart")) then
360
                    continue
361
                end
362
363
                -- // Check it
364
                CheckTargetPart(v)
365
            end
366
        else
367
            -- // Individual
368
            CheckTargetPart(TargetParts)
369
        end
370
    end
371
372
    -- //
373
    if (typeof(TargetParts) == "table") then
374
        -- // Loop through all target parts and check them
375
        for _, TargetPartName in ipairs(TargetParts) do
376
            CheckTargetPart(TargetPartName)
377
        end
378
    end
379
380
    -- //
381
    return ClosestPart, ClosestPartPosition, ClosestPartOnScreen, ClosestPartMagnitudeFromMouse
382
end
383
384
-- // Silent Aim Function
385
function Aiming.GetClosestPlayerToCursor()
386
    -- // Vars
387
    local TargetPart = nil
388
    local ClosestPlayer = nil
389
    local Chance = CalcChance(Aiming.HitChance)
390
    local ShortestDistance = 1/0
391
392
    -- // Chance
393
    if (not Chance) then
394
        Aiming.Selected = LocalPlayer
395
        Aiming.SelectedPart = nil
396
397
        return LocalPlayer
398
    end
399
400
    -- // Loop through all players
401
    for _, Player in ipairs(GetPlayers(Players)) do
402
        -- // Get Character
403
        local Character = Aiming.Character(Player)
404
405
        -- // Make sure isn't ignored and Character exists
406
        if (Aiming.IsIgnored(Player) == false and Character) then
407
            -- // Vars
408
            local TargetPartTemp, _, _, Magnitude = Aiming.GetClosestTargetPartToCursor(Character)
409
410
            -- // Check if part exists and health
411
            if (TargetPartTemp and Aiming.CheckHealth(Player)) then
412
                -- // Check if is in FOV
413
                if (circle.Radius > Magnitude and Magnitude < ShortestDistance) then
414
                    -- // Check if Visible
415
                    if (Aiming.VisibleCheck and not Aiming.IsPartVisible(TargetPartTemp, Character)) then continue end
416
417
                    -- // Set vars
418
                    ClosestPlayer = Player
419
                    ShortestDistance = Magnitude
420
                    TargetPart = TargetPartTemp
421
                end
422
            end
423
        end
424
    end
425
426
    -- // End
427
    Aiming.Selected = ClosestPlayer
428
    Aiming.SelectedPart = TargetPart
429
end
430
431
-- // Heartbeat Function
432
Heartbeat:Connect(function()
433
    Aiming.UpdateFOV()
434
    Aiming.GetClosestPlayerToCursor()
435
end)
436
437
-- //
438
return Aiming
439
440
-- // If you want the examples, look at the docs.