Raycast only works if you walk into the bullet

You can write your topic however you want, but you need to answer these questions:

  1. I would like it to work if the bullet hits you not if you walk into it

  2. you have to walk into the bullet for it to kill you or even register that the ray hit you

  3. Ive tried not looping it, which did nothing, i tried throwing it in a coroutine just cause and thats it.

heres the code chunk

while wait() do
local ray = Ray.new(bullet.Position,bullet.CFrame.LookVector*9)
local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{char})
if hit and hit.Parent == nil then	
		elseif hit and hit.Parent:findFirstChild("Humanoid") and hit.Parent.Name ~= char.Name and hit.Parent.Name ~= "Glock" and deb == false and hit.Parent.Humanoid.Health > 1 then
			deb = true
			 hit.Parent.Humanoid.Health = 1
		
plyr.stats.gun_folder.ammo.Value = plyr.stats.gun_folder.ammo.Value + 1
plyr:WaitForChild("leaderstats"):WaitForChild("Gun Kills").Value = plyr:WaitForChild("leaderstats"):WaitForChild("Gun Kills").Value + 1
print("found")
			bullet:Destroy()
			deb = false
		elseif deb == true then
print("nosir")
		else

				
		end
		end

Because you didn’t create the bullet when there is no humanoid
At least I don’t see it

There’s no reason to use while loops, because the ray should go forward by itself,
yes it doesn’t fix the problem but remove it

alright, so remove the while loop, it dosent need looped, gotya, seems like if i remove it you cant even walk into it to die though.

i created a bullet, this is just the raycasting chunk, its not the whole script

yea! that’s how you do it! don’t follow what works, follow the logic!

Any ideas on my main issue here though?

read this up first

30charschars

What do you mean create a bullet when there is no humanoid? am I misunderstanding something?

also,

if hit and hit.Parent == nil

is just messed up, you can’t hit something that has a parent of nil.

I guess you have a point there lol

if it helps im anchoring the bullet and moving it by tween