I have a raycast, and if it returns no instance, then the result is going to be the users mouse.Hit. The problem is that the distance beetween the firepos and mouse.hit.position is bigger than the max part size (2048) so how would i limit this?
local raycast = workspace:Raycast(Tool.FirePos.Position,(Mouse.Hit.Position-Tool.FirePos.Position)+Vector3.new(Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value),Random.new():NextNumber(-Values.Spread.Value,Values.Spread.Value))*1.2)
local result
local origin = Tool.FirePos.Position
local target
if raycast then
result = raycast
else
result = Mouse.Hit
end
local distance = (origin - result.Position).Magnitude
local p = Instance.new("Part")
p.Size = Vector3.new(0.1, 0.1, distance)
p.CFrame = CFrame.lookAt(origin, result.Position)*CFrame.new(0, 0, -distance/2)
p.Parent = workspace
game.Debris:AddItem(p,.05)