I made a gun script that deals damage to player’s Humanoid
but the problem is that I want it to deal double the damage if the Raycast hits the player’s head just like a headshot
Here is my script
local DamagePlayer = game.ReplicatedStorage.DamagePlayer
local range = 300
DamagePlayer.OnServerEvent:Connect(function(player, MousePosition, Origin)
script.Parent.GunShot:Play()
local direction = (MousePosition - Origin).Unit * range
local rayParams = RaycastParams.new()
rayParams.FilterDescendantsInstances = {player.Character}
rayParams.FilterType = Enum.RaycastFilterType.Blacklist
local results = workspace:Raycast(Origin, direction)
if results then
local Character = results.Instance.Parent
local Humanoid = Character:FindFirstChild("Humanoid")
if Humanoid then
Humanoid:TakeDamage(20)
elseif Character:FindFirstChild("Head") then
Humanoid:TakeDamage(30)
end
end
end)
I don’t want to change anything in my script I just want a solution to my Problem
What should i do to fix this?
Is there a specific function for this?