Player gets damaged by his own weapon

So when the player shoots they damage themselves. I want it to have a hit function so I’m able to change the mouse icon when a humanoid is hit. I have put it into a hit function but it didn’t work.

local Script

Server Script

I have changed the script up for hours but either the player gets damaged or the script won’t damage the humanoid. It is something wrong with line 30 on the server side

if humanoid and humanoid.Name ~= player.Name then
    humanoid:TakeDamage(30)
end
3 Likes

If you shoot at the legs the player takes damage

Where have you pasted my code?

Try adding a print(player.Name, humanoid.Name) to check for inconsistencies.

1 Like


In the server script
(“Players Humanoid”)
(“TheFishThief Humanoid”)

You’ve miscopied my code.

player.Name, not Players.Name.

1 Like

local Players = game:GetService(“Players”)
local ClientPlayer = Players.LocalPlayer
I passed it with a remote Event

if humanoid and humanoid.Name ~= ClientPlayer.Name then
humanoid:TakeDamage(10)
end

Is still not the same.

Use the code I originally wrote in my first reply.

Realistically, you don’t need ClientPlayer as a variable. The first argument on a server-fired RemoteEvent is the player that fired the event.

1 Like
if humanoid and part.Name ~= player.Name then
	if part.parent.Name ~= player.Name then
		humanoid:TakeDamage(30)
	end
end

One of them will get it right. With both you should have it either way.

This is most likely the real answer.

if humanoid and part.parent.Name ~= player.Name then
		humanoid:TakeDamage(30)
end
1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.