So basicly when the beam hits it does 50 damage on all parts but on head I want to take 100 damage the problem is it only takes 50 damage.
script:
local range = 400
local NormalDamage = 50
local HeadDamage = 100
[...]
local NewRay = RaycastParams.new()
local RayDirection = (TargetLocation - BulletLocation.Position) * range
NewRay.FilterDescendantsInstances = {Player.Character}
local Result = game.Workspace:Raycast(BulletLocation.Position, RayDirection, NewRay)
if Result then
if Result.Instance then
if Result.Instance.Parent:FindFirstChild("Humanoid") then
Result.Instance.Parent.Humanoid.Health -= NormalDamage
elseif Result.Instance.Parent:FindFirstChild("Head") then -- Trying to get the head
Result.Instance.Parent.Humanoid.Health -= HeadDamage -- does the 100 damage
end
end
end
end)
I assume every time the beam hits something, it will hit an instance where its parent has a humanoid has their child. Every time this if statements checks the condition, if it is true then the other elseif statements will be ignored, so you should do the if statement of checking if it has a head inside the scope of the first if statement.
Wait I changed something I tried to use by the name
if Result then
if Result.Instance then
if Result.Instance.Name == "Head" then
humanoid.Health -= HeadDamage
else
humanoid.Health -= NormalDamage
end
end
end
end)
It works the problem is after that I get this error
ServerScriptService.Script:39: attempt to index nil with 'Health' - Server - Script:39
I think is only when I miss or something.