local function createRay(tool,filter,mousePosition,range)
if tool:FindFirstChild("Handle")then
local rayOrigin = tool.Handle.Position
local rayDirection = (mousePosition - rayOrigin).unit*range
local raycastParams = RaycastParams.new()
raycastParams.FilterDescendantsInstances = {filter}
raycastParams.FilterType = Enum.RaycastFilterType.Blacklist
local raycastResult = workspace:Raycast(rayOrigin, rayDirection, raycastParams)
if raycastResult then
print("raycasted")
local hitPart = raycastResult.Instance
tempBullet(rayOrigin,raycastResult.Position)
else
end
end
end
Many tutorials I've seen use
local rayDirection = (mousePosition - rayOrigin)*range--this is wrong because it makes the range way too high instead of
local rayDirection = (mousePosition - rayOrigin).unit*range
When I use the one with .unit, it works only in the ranges that are not passed what I set the range to. lets say range = 50 if I click anywhere passed 50 studs the ray isn't even created

1 comment
I'm not sure if I am fully understanding your question, but couldn't you raise your raycast range to be higher? Lets say 1000000 instead of 50?