I am working on a gun, and everything is working as it should, but I have one problem: Hats keep getting in the way of headshots etc. Any way to have a ray ignore hats? Here is the raycast section of my main script...
local ray = Ray.new(tool.Barrel.CFrame.p, (mouse.Hit.p - tool.Barrel.CFrame.p).unit*300) local hit, position = game.Workspace:FindPartOnRay(ray, user) script.Parent.Handle.Fire:Play() local humanoid = hit and hit.Parent and hit.Parent:FindFirstChild("Humanoid") if humanoid then if not hit.Parent:FindFirstChild("ForceField") then if hit.Name == "Torso" then humanoid:TakeDamage(70) elseif hit.Name == "Head" then humanoid:TakeDamage(87) humanoid.WalkSpeed = 14 else humanoid:TakeDamage(45) end end humanoid.Died:connect(function() if enabled == true then giveKills(hit.Parent) enabled = false end end) end
Well, You can't really make the ray ignore the hat, But you can edit your script too see if the hit.Parent:IsA("Hat")
if Hit.Parent:IsA("Hat") then --Do the regular damaging part of the script else -- You would have to set everything to hit.Parent.Parent.Humanoid, Which would allow it to damage the humanoid. end