0% found this document useful (0 votes)
87 views2 pages

Da

This document contains code that gets the closest player to the local player and modifies mouse and raycast functions to target the closest player's head and character. It connects a key press to toggle targeting by team. The code overrides metatable functions and hooks a workspace function to modify raycast behavior.

Uploaded by

disbelieve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
87 views2 pages

Da

This document contains code that gets the closest player to the local player and modifies mouse and raycast functions to target the closest player's head and character. It connects a key press to toggle targeting by team. The code overrides metatable functions and hooks a workspace function to modify raycast behavior.

Uploaded by

disbelieve
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

local localPlayer = game:GetService("Players").

LocalPlayer
local mouse = localPlayer:GetMouse()
local teamCheck = true

local function getClosestPlayer()


local closestPlayer = nil
local shortestDistance = math.huge

for i, v in pairs(game:GetService("Players"):GetPlayers()) do
if v.Name ~= localPlayer.Name then
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
local magnitude = (v.Character.HumanoidRootPart.Position -
localPlayer.Character.HumanoidRootPart.Position).magnitude

if magnitude < shortestDistance then


closestPlayer = v
shortestDistance = magnitude
end
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
local magnitude = (v.Character.HumanoidRootPart.Position -
localPlayer.Character.HumanoidRootPart.Position).magnitude

if magnitude < shortestDistance then


closestPlayer = v
shortestDistance = magnitude
end
end
end
end

return closestPlayer
end

game:GetService("UserInputService").InputBegan:Connect(function(input, onGui)
if not onGui and input.KeyCode == Enum.KeyCode.T then
teamCheck = not teamCheck
end
end)

local mt = getrawmetatable(game)
local oldIndex = mt.__index
local oldNamecall = mt.__namecall
if setreadonly then setreadonly(mt, false) else make_writeable(mt, true) end
local nameCallMethod = getnamecallmethod or get_namecall_method
local newClose = newcclosure or function(f) return f end

mt.__index = newClose(function(t, k)
if t == mouse and tostring(k) == "Hit" then
if getClosestPlayer().Character and
getClosestPlayer().Character:FindFirstChild("Head") then
return getClosestPlayer().Character.Head.CFrame
end
end
return oldIndex(t, k)
end)

mt.__namecall = newClose(function(...)
local method = nameCallMethod()
local args = {...}

if tostring(method) == "FindPartOnRayWithIgnoreList" and getClosestPlayer() and


getClosestPlayer().Character then
return oldNamecall(args[1], args[2],
{game:GetService("Workspace").IgnoreThese,
game:GetService("Players").LocalPlayer.Character,
game:GetService("Workspace").BuildStuff, game:GetService("Workspace").Map})
end

return oldNamecall(...)
end)

if setreadonly then setreadonly(mt, true) else make_writeable(mt, false) end

local oldFunc

oldFunc = hookfunction(workspace.FindPartOnRayWithIgnoreList, function(...)


local args = {...}

args[3] = {game:GetService("Workspace").IgnoreThese,
game:GetService("Players").LocalPlayer.Character,
game:GetService("Workspace").BuildStuff, game:GetService("Workspace").Map}

return oldFunc(unpack(args))
end)

You might also like