Im trying to make it so when the gun hits a player it will do damage which I have successfully done. But when I hit like an accessory It wont work because of the way the script is. Its set so when the raycast his a player is prints its instance name and then from that I find the parent then the humanoid. I want to do something like findfirstparent(The players character) then do something like .Humanoid Can someone help me out on this?
Ill show my code and what happens when you shoot someone
local hitPart = ray.Instance
if hitPart then
local hitModel = hitPart:FindFirstAncestorOfClass("Model")
if hitModel then
local hitHuman = hitModel:FindFirstChildOfClass("Humanoid")
if hitHuman then
hitHuman:TakeDamage(hitHuman.Health)
end
end
end
ray.Instance is nil if the casted ray does not intercept a BasePart instance.