View difference between Paste ID: ABfZubuX and QFPsrUWj
SHOW: | | - or go back to the newest paste.
1
local localPlayer = game:GetService("Players").LocalPlayer
2
local teamCheck = true
3
4
function getClosestPlayer()
5
    local closestPlayer = nil
6
    local shortestDistance = math.huge
7
    
8
    for i, v in pairs(game:GetService("Players"):GetPlayers()) do
9
        if v.Name ~= localPlayer.Name then
10
            if v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") and teamCheck and v.Team ~= localPlayer.Team then
11
                local magnitude = (v.Character.HumanoidRootPart.Position - localPlayer.Character.HumanoidRootPart.Position).magnitude
12
13
                if magnitude < shortestDistance then
14
                    closestPlayer = v
15
                    shortestDistance = magnitude
16
                end
17
            elseif v.Character and v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Health ~= 0 and v.Character:FindFirstChild("HumanoidRootPart") and v.Character:FindFirstChild("Head") and not teamCheck then
18
                local magnitude = (v.Character.HumanoidRootPart.Position - localPlayer.Character.HumanoidRootPart.Position).magnitude
19
20
                if magnitude < shortestDistance then
21
                    closestPlayer = v
22
                    shortestDistance = magnitude
23
                end
24
            end
25
        end
26
    end
27
    
28-
    return closestPlayer or localPlayer
28+
    return closestPlayer
29
end
30
31
game:GetService("UserInputService").InputBegan:Connect(function(input, onGui)
32
    if not onGui and input.KeyCode == Enum.KeyCode.T then
33
        teamCheck = not teamCheck
34
    end
35
end)
36
37
local mt = getrawmetatable(game)
38
local oldNamecall = mt.__namecall
39
if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
40
local namecallMethod = getnamecallmethod or get_namecall_method
41
local newClose = newcclosure or function(f) return f end
42
43
mt.__namecall = newClose(function(...)
44
    local method = namecallMethod()
45
    local args = {...}
46
47-
    if tostring(method) == "FireServer" and tostring(args[1]) == "HitPart" then
47+
    if tostring(method) == "FireServer" and tostring(args[1]) == "HitPart" and getClosestPlayer().Character and getClosestPlayer().Character:FindFirstChild("Head") then
48
        args[2] = getClosestPlayer().Character.Head
49
        args[3] = getClosestPlayer().Character.Head.Position
50
51
        return oldNamecall(unpack(args))
52
    end
53
54
    return oldNamecall(...)
55
end)
56
57
if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end