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
The Direction of your ray constructor is wrong, using lookvector will only make the ray cast straight in front of your head, you need to get the direction of where the ray is supposed to cast
Im assuming your char is referencing the player character
local ray = Ray.new(mouse.Hit.p,(mouse.hit.p-char.Head.Position).unit*999)
Here i made a gun to show what will happen if you use lookvector: https://gyazo.com/cd5015c1afdf5437918c00101ce94eee
And if you constructed the ray correctly: https://gyazo.com/2f957a27cd63375072a9fb1aea9a7a45
Note that the beams are being blocked by other beams because i didnt add beams to the ignorelist