NPC with shield still taking damage

I am trying to make an enemy variation that has a shield but somehow still takes damage when I shoot the shield.

NPC in game
image

NPC in explorer

Show us the script which damages the npc and make sure that shield.CanTouch = true

The way I handled shields was with the shooter.

Basically, you create a check in your code before damage is done to check if the target has a shield equipped. Then if the target does have a shield you can change the damage amount.

We need to see your script to give a proper solution.
However, from what I can tell, your script might be checking if the part hit is owned by the character, which includes the shield, so it might be assuming the shield is a regular bodypart

1 Like

Iā€™m using Roblox Endorsed Weapons Kit

In line 409 in the WeaponSystem module we can find

function WeaponsSystem.getHumanoid(part)
	while part and part ~= workspace do
		if part:IsA("Model") and part.PrimaryPart and part.PrimaryPart.Name == "HumanoidRootPart" then
			return part:FindFirstChildOfClass("Humanoid")
		end

		part = part.Parent
	end
end

This tries to find the humanoid of a model by checking its parent and then checking the parent of the parent and so on until it gets to the workspace or finds one.

Since your shield is part of the character itself, it will think that the shield acts as a regular part of the character.

You have to add an if statement to only proceed with the damage if the instance hit is NOT part of a shield
e.g if part.Name == "RiotShield" then return end which will nullify the damage

2 Likes

Had to change it to:

if part:IsA("Model") and part.PrimaryPart.Name == "RiotShield" or part.Name == "RiotShield" then return

But it works, thanks!