Gun wont kill a player

I am confused why my gun wont kill any zombie or player, when the bullet touches the zombie it won’t kill them. Here is the area of code for the gun when it kills them or shoots.

	if hit then
			if hit.Parent:FindFirstChild("Humanoid") then
				print("heat it up")
				game.ReplicatedStorage.RemoveHP:FireServer(hit.Parent.Name,gunset.damage)
			 if hit.Parent.Humanoid.Health <= 0 then
				print("they ded")
        game.ReplicatedStorage.KillEvent:FireServer()
else

Now the server

game.ReplicatedStorage.RemoveHP.OnServerEvent:Connect(function(player,player2,dmg)
	print(player2.Name)
	local plr = game.Workspace:FindFirstChild(player2.Name)
	if plr then
plr.Humanoid:TakeDamage(dmg)
	end
end)

We do have an error, but I am confused what it’s referring to.

Error:

Argument 1 missing or nil
--Says the error is Line 3 of the serverside script.

If anyone could help, would appreciate it!

game.ReplicatedStorage.RemoveHP:FireServer(hit.Parent.Name,gunset.damage)

you’re sending a string, and from the server you’re indexing that string so say you shot me, ("incapaz").Name evaluates to nil.

game.ReplicatedStorage.RemoveHP.OnServerEvent:Connect(function(player,player2,dmg)
	print(player2)
	local plr = game.Workspace:FindFirstChild(player2)
	if plr then
plr.Humanoid:TakeDamage(dmg)
	end
end)

This code can severely be abused by exploiters. They can pass an arbitrary amount of damage and an arbitrary username. You’re trusting the client. Don’t trust the client. Ever. You may need to restructure your code so that it cannot be abused.

1 Like

The first Argument you sent was “hit.Parent.Name”

Then here you went on and wrote “player2.Name”, player2 being “hit.Parent.Name”

What an embarrassing mistake. Thanks for the help!