I have a ray casting pistol but if you hit a hat it doesn't register. Things I've tried to get it to find the humanoid through the hat.
local hum = hit.Parent:FindFirstChild("Humanoid") if not hum then hum = hit.Parent.Parent:FindFirstChild("Humanoid") end
First, you check if the name of the hat. Hats work like tools, they need a part named "Handle" to work. Here is the code. Only for checking.
if hit.Name == "Handle" and hit.Parent:IsA("Accoutrement") then -- Accessories and hats (deprecated) inherit from this class. -- do code end