I'm not really good at raycasting so I don't know how to do stuff. Really I wanted to use Filtering Enabled but I can't access my weapon with a server script due to it being in the camera unless I learn. Any help would be appreciated
function createRay()
local muzzle = gun[gun.Name].Flash
local ray = Ray.new(mouse.Hit.p,muzzle.CFrame.lookVector*999)
local hit,pos = workspace:FindPartOnRayWithIgnoreList(ray,{char})
if hit then
local human = hit.Parent:FindFirstChild("Humanoid")
if human then
print(hit.Name)
if human.Health >0 then
player.PlayerGui.HUD.Crosshair.Hit:Play()
player.PlayerGui.HUD.Crosshair.Frame.Hitmarker.Visible = true
if hit.Parent == "Head" then
human:TakeDamage(s.dmg * s.multi)
elseif hit.Parent:IsA("Part") then
human:TakeDamage(s.dmg * s.damage)
elseif hit.Parent:FindFirstChild("Humanoid") then
human:TakeDamage(s.dmg)
end
end
end
end
end
Sometimes the ray wouldn't detect the head even though I'm aiming straight at it. Not sure why? Even the Upper Torso. Maybe I should try R6 instead

7 comments
I can't test it due to roblox being down but thanks for the help!
No problem, any errors with your script feel free to come back and ask, so long as you attempted it
of course! I always try things first
oh I almost forgot the raycast won't do damage in game though what do I have to do here?
change the health property of the humanoid, you already got the humanoid in the variable human
lol, at your video you forgot to use the ":destroy" thing, so the bullet will just float arround for ever
yes i did that intentionally for the sake of this demonstration