I’m trying to make a gun system with headshots. I’m trying to find a method to detect the head of the opposing player. What I’ve tried is the following script below, the issue with the script is it detects the entire character as one while I only need the bullet to detect the head.
Script:
local part = bullet --shortened down
local head = part.Parent:FindFirstChild('Head') or part.Parent.Parent:FindFirstChild('Head') or (part.Parent.Parent.Parent and part.Parent.Parent.Parent:FindFirstChild('Head')) -- this is the line that I need to change
if head then... --do the damage
Found a script online that shows how headshots can work with modifications.
Credits to the user who made this script
local bullet = script.Parent
local headshot_sound = game.Workspace.HEADSHOT
local function player_check(otherPart)
local humanoid = otherPart.Parent:FindFirstChild('Humanoid')
if humanoid and humanoid.Parent.Name ~= bullet.Attacker.Value then
if otherPart.Name == 'Head' then
humanoid:TakeDamage(100)
headshot_sound:Play()
else
humanoid:TakeDamage(30)
end
local player = game.Players:FindFirstChild(humanoid.Parent.Name)
if player then
local tag = player:FindFirstChild('Killer')
if tag then
tag.Value = bullet.Attacker.Value
bullet:Destroy()
end
end
end
end
bullet.Touched:Connect(player_check)