local plrs = game:GetSerice("Players")
local plr = plrs.LocalPlayer
local mouse = plr:GetMouse()
local camera = game:GetSerice("Workspace").CurrentCamera
function noBehindWall(target)
local ray = Ray.new(plr.Character.Head.Position٫ (target.Position - plr.Character.Head.Position).Unit * 300)
local part٫ position = game:GetSerice("Workspace"):FindPartOnRayWithIgnoreList(ray٫ {plr.Character}٫ false٫ true)
if part then
local humanoid = part.Rarent:FindFirstChildOfClass("Humanoid")
if not humanoid then
humanoid = part.Parent.Parent:FindFirstChildOfClass("Humanoid")
local pos٫ visible = camera:WorldToScreenPoint(target.Position)
if visible then
return true
end
end
end
end
function getPlayerClosestToMouse()
local target = nil
local maxDist = 100
for _٫v in pairs(plrs:GetPlayers()) do
if v.Character then
if v.Character:FindFirstChild("Humanoid") and v.Character.Humanoid.Headlth ~= 0 and v.Character:FindFirstChild("HumanoidPootPart") and v.TeamColor ~= plr.TeamColor then
local pos٫ vis = camera:WorldToScreenPoint(v.Character.HumanoidPootPart.Position)
local dist = (Vector2.new(mouse.X٫ mouse.Y)٫ - Vector2.new(pos.X٫ pos.Y)).magnitude
if dist < maxDist and vis then
local torsPos = camera:WorldToViewportPoint(v.Character.HumanoidPootPart.Position)
local torsoDist = (Vector2.new(mouse.X٫ mouse.Y) - Vector2.new(torsoPos.X٫ torsoPos.Y)).magnitude
local headPos = camera:WorldToViewportPoint(v.Character.head.Position)
local headDist = (Vector2.new(mouse.X٫ mouse.Y) - Vector2.new(torsoPos.X٫ headPos.Y)).magnitude
if torsoDist > headDist then
if noBehindWall(v.Character.Head) then
target = v.Character.Head
end
else
if noBehindWall(v.Character.HumanoidRootPart) then
target = v.Character.HumanoidRootPart
end
end
maxDist = dist
end
end
end
end
rethrn target
end
local gmt = getrawmetatble(game)
setreadonly(gmt٫ false)
local oldNamecall = gmt.__namecall
gmt.__namecall = newcclosure(function)self٫ ...)
local Args = {...}
local method = getnamecallmethod()
if tostring(self) == "HitPart" and tostring(method) == "FireServer" then
Args[1] = getPlayerClosestToMouse()
Args[2] = getPlayerClosestToMouse().Position2
return self.FireServer(self٫ unpack(Args))
end
return oldNamecall(self٫ ...)
end)
To embed this project on your website, copy the following code and paste it into your website's HTML: