Gun not damaging the npc

Hi , I’m trying to make a gun for some reason it’s not damaging the Humanoid.
Here’s the local script:

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
	if mouse.Target:FindFirstChild("Humanoid") then
		local target = mouse.Target.Parent
		game.ReplicatedStorage.Events.GunshotPistol:FireServer(target)
	end
end)

server script:

game.ReplicatedStorage.Events.GunshotPistol.OnServerEvent:Connect(function(target)

target.Humanoid.Health = target.Humanoid.Health -15

end)
1 Like

You’re getting the part that the mouse targeted, not the model itself. I would suggest using mouse.Target.Parent:FindFirstChild("Humanoid") to get the entire model and then find the humanoid object.

1 Like

I get the error “Humanoid” is not a valid member of Players.Cats767_99

The humanoid isn’t in the player object, it’s in the player’s character.

Do Target.Humanoid.Health = Target.Humanoid.Health - 15

I know but that’s just what I get in the output.

Or you could do Target.Humanoid:TakeDamage(15)

I’m still getting the error Humanoid is not a valid member of Players.Cats767_99

Pass the Player Object target is what u get off of game.Players.Cats767_99

Ah, I forgot that you had a remote event, my bad lol.

RemoteEvents on the server’s side take the player as the first parameter, so your script has confused ‘target’ as the player.

game.ReplicatedStorage.Events.GunshotPistol.OnServerEvent:Connect(function(player, target)

target.Humanoid.Health = target.Humanoid.Health -15

end)

And I would suggest that you use what @ThoseNamesAreGood suggested and use Humanoid:TakeDamage() instead of subtracting health.

try printing target and tell us what it says.

1 Like

Humanoid Is not a valid member of HumanoidRootPart ;-;

Like I said earlier, you’re getting the individual parts instead of the entire character. Make sure you use mouse.Target.Parent to get the entire character instead of individual parts.

Well… Not sure will this work or not

The local script :

local mouse = game.Players.LocalPlayer:GetMouse()
mouse.Button1Down:Connect(function()
   if mouse.Target.Parent:FindFirstChild("Humanoid") then
   	local target = mouse.Target.Parent
   	game.ReplicatedStorage.Events.GunshotPistol:FireServer(target)
   end
end)

Server script:

game.ReplicatedStorage.Events.GunshotPistol.OnServerEvent:Connect(function(player, target)

target.Humanoid:TakeDamage(15)

end)

I am using that for some reason it’s not working.

Then you must have parts that are children of the HumanoidRootPart. Try using mouse.Target:FindFirstAncestorWhichIsA("Humanoid")

Or you could change mouse.Button1Down to script.Parent.Activated if the local script parent is a tool

FindFirstAncestortWhichIsA is not a valid member of Part “Workspace.Cats767_99.HumanoidRootPart” - Client - LocalScript:3
Maybe I should use raycasting instead?

You misspelled ‘Ancestor’ as ‘Ancestort’.

No errors but it doesn’t kill the npc.