ok… I’ve changed it to Mouse.Hit.Position as you said, yes its the same. Still inaccurate
local function CastRay(Type, StartPos, Direction, Length, Blacklist, IgnoreWater, RealTargetHumanoid)
debug.profilebegin("CastRay_(GunClient_"..Tool.Name..")")
local Blacklist = CloneTable(Blacklist)
local ShouldIgnoreHumanoid = CurrentModule.IgnoreHumanoids
if Type ~= "Beam" then
ShouldIgnoreHumanoid = false
end
local Iterations = 0
local NewRay = Ray.new(StartPos, Vector3.new(Direction.X, 0, Direction.Z) * Length)
local HitPart, HitPoint, HitNormal, HitMaterial = nil, StartPos + (Direction * Length), Vector3.new(0, 1, 0), Enum.Material.Air
while Iterations < 20 do
Iterations = Iterations + 1
HitPart, HitPoint, HitNormal, HitMaterial = Workspace:FindPartOnRayWithIgnoreList(NewRay, Blacklist, false, IgnoreWater)
if HitPart then
local Target = HitPart:FindFirstAncestorOfClass("Model")
local TargetHumanoid = Target and Target:FindFirstChildOfClass("Humanoid")
local TargetTool = HitPart:FindFirstAncestorOfClass("Tool")
if RealTargetHumanoid and TargetHumanoid then
ShouldIgnoreHumanoid = (RealTargetHumanoid ~= TargetHumanoid)
end
if (--[[not HitPart.CanCollide
or]] HitPart.Transparency > 0.75
or HitPart.Name == "Handle"
or (
TargetHumanoid and (
TargetHumanoid.Health <= 0
or not DamageModule.CanDamage(Target, Character, CurrentModule.FriendlyFire)
or ShouldIgnoreHumanoid
)
)
or TargetTool) then
table.insert(Blacklist, HitPart)
else
break
end
else
break
end
end
debug.profileend()
return HitPart, HitPoint, HitNormal, HitMaterial
end
local function Get3DPosition(Type)
local EndPos = Mouse.Hit.Position
local HitPart, HitPoint, HitNormal, HitMaterial = CastRay(Type, Camera.CFrame.p, (EndPos - Camera.CFrame.p).Unit, 1000, IgnoreList, true)
return HitPoint
end
local function Get3DPosition2()
local Type = CurrentModule.LaserBeam and "Beam" or "Tip"
if Module.DirectShootingAt == "None" then
return Get3DPosition(Type)
else
local FirePointObject = HandleToFire:FindFirstChild("GunFirePoint"..CurrentFireMode)
if FirePointObject ~= nil then
local Direction = ((FirePointObject.WorldCFrame * CFrame.new(0, 0, -5000)).p - FirePointObject.WorldPosition).Unit
local HitPart, HitPoint, HitNormal, HitMaterial = CastRay("Direct", FirePointObject.WorldPosition, Direction, 5000, IgnoreList, true)
if Module.DirectShootingAt == "Both" then
return HitPoint
else
if Module.DirectShootingAt == "FirstPerson" then
if (Camera.Focus.p - Camera.CoordinateFrame.p).Magnitude <= 2 then
return HitPoint
else
return Get3DPosition(Type)
end
elseif Module.DirectShootingAt == "ThirdPerson" then
if (Camera.Focus.p - Camera.CoordinateFrame.p).Magnitude > 2 then
return HitPoint
else
return Get3DPosition(Type)
end
end
end
else
return Get3DPosition(Type)
end
end
end