Hello! I am making an FPS game using R6 characters. I have a problem in which my code cant tell if the shot should do headshot damage or bodyshot damage.
The problem is parts such as the Handler’s in character’s hats and other accessories. Since these accessories are not parented to the head how am I supposed to tell if I should do a body or head shot?
Is there a way for my raycast to ignore these parts or something?
Here is my current code:
local origin = self.mouse.UnitRay.Origin
local direction = self.mouse.UnitRay.Direction
local ignore = {self.character, self.camera, self.weapon
local ray = Ray.new(origin, direction * self.settings.firing.distance)
local hit, hitPos = workspace:FindPartOnRayWithIgnoreList(ray, ignore)
if hit then
local partParent = hit:FindFirstAncestorWhichIsA("Model")
local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
if humanoid then
if hit.Name == "Head" then
print("headshot")
else
print("bodyshot")
end
end