So with this ray-cast method, the idea is that the ray will continuously recast as the bullet part moves. For testing purposes, I have it printing the object it hits. When you start testing, when if you shoot at an object, it'll work fine and print the name; however, as soon as you shoot into the sky and the ray hits nothing, for whatever reason, it stops printing even if you start shooting objects again. Why is that? Here's the code:
function CastRay()
local h,p
local p0 = Bullet.Position;
while true do
rs:wait()
local p1 = Bullet.Position;
h, p = workspace:FindPartOnRayWithIgnoreList(Ray.new(p0,(p1 - p0)), Ray_Ignore);
if distance > 1000 then
break
end
if h then
print(h.Name)
return h, p;
end
distance = distance + (p1 - p0).magnitude
p0 = p1;
end
end

1 comment
Is distance global? This code alone should work. I'm thinking the actual problem is somewhere else in the script. I'd use a spawn function to your loop. That would basically allow the rest of the code to run by taking turns in a sense.