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

4 comments
Thanks, it worked!
No problem.
if it IS a hat, continue? and if NOT, do different stuff?
And on top of that, there is no reason to use :isA() if you're just checking the class, and i believe it may be slower.