For some reason, when raycasting a bullet, the raycast will print nil when shooting at the player’s head or the top of the arm, but it works just fine when shooting at the lower arm or at any other body part.
local raycastresult = workspace:Raycast(script.Parent.BulletPart.Position,(mousePos - script.Parent.Handle.Position)*300000,raycastparams)
print(mousePos)
print(raycastresult)
print(raycastresult)
if raycastresult then
local hp = raycastresult.Instance
print(hp)
print(hp.Parent)
print(hp.Parent.Parent)
local model = hp:FindFirstAncestorOfClass("Model")
if model or hp.Name == "Left Arm" or hp.Name == "Right Arm" then
if model:FindFirstChild("Humanoid") or hp.Name == "Left Arm" or hp.Name == "Right Arm" then
if dmgdb == false then
if model.Name == script.Parent.Parent.Name then
print("hit self")
else
if hp.Name == "Left Leg" or hp.Name == "Right Leg" then
script.Parent.DAMAGE:FireClient(player,game.Players:GetPlayerFromCharacter(model),85)
wait(.1)
script.Parent.BulletPart.Hit:Play()
if model.Humanoid.Health ~= 0 and model.Humanoid.Health <= 15 then
script.Parent.BulletPart.KillSound:Play()
player.leaderstats.Kills.Value += 1
game.ReplicatedStorage.KillGui:FireClient(player, model)
game.ReplicatedStorage.Alive.Value -= 1
elseif model.Humanoid.Health ~= 0 and model.Humanoid.Health >= 15 then
model.Humanoid.Health -= 85
end
wait(2)
script.Parent.BulletPart.KillSound:Stop()
script.Parent.BulletPart.Hit:Stop()
else
script.Parent.DAMAGE:FireClient(player,game.Players:GetPlayerFromCharacter(model),100)
script.Parent.BulletPart.Hit:Play()
if model.Humanoid.Health ~= 0 then
script.Parent.BulletPart.KillSound:Play()
game.ReplicatedStorage.KillGui:FireClient(player, model)
model.Humanoid.Health -= 100
player.leaderstats.Kills.Value += 1
game.ReplicatedStorage.Alive.Value -= 1
end
wait(2)
script.Parent.BulletPart.KillSound:Stop()
script.Parent.BulletPart.Hit:Stop()
end
end
end
else
wait(difference)
if hp.Parent ~= script.Parent then
end
end
else
wait(difference)
if hp.Parent ~= script.Parent then
end
end
end