How do I detect where the humanoid was damaged from?

So im trying to make something where when somebody is hit in the arm it turns green and mummified that sort of thing. Thing is idk how im supposed to detect if the arm was hit.

1 Like

How do you do damage in the first place? Could you show your code?

Im not sure what you mean by that. I havent wrote a script yet im just asking how i can do it before i actually start scripting. Well i think i can make a script where when the humanoid was damaged it will see if any of the parts were touched (because im gonna be using swords or other melee weapons not guns) but im not sure how to do it because im only a beginner but i’ll try.


local hum = script.parent:Waitforchild("Humanoid")

hum.HealthChanged:Connect(function(part)
if script.parent.LeftLeg.Touched

i dont really know what to do next after that.

1 Like

The best way I can think of doing this is basically do the color changing code from the weapon itself.

script.Parent.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") and hit.Name == "LeftLeg" then
hit.Color = Color3.fromRGB(0,146,0)
end
end)

im going to guess its a tool with a part the deals the damage:

script.Parent.DamagePart.Touched:Connect(function(hit)
	--hit will be were it was touched, you will have to do checks to make sure it was hit by a player part for example:
	if hit.Parent:FindFirstChild("Humanoid") then
		hit.Color = Color3.fromRGB(68, 255, 0)
	end
end)

hope this helps, i will send the model link:
https://create.roblox.com/marketplace/asset/10682304413/Sword

@MAcres600 and @ayoub50 thanks for helping but i wanna know how i can do it from the character model not a tool.

I dont know if its possible.

it is possible
put this in StarterCharacterScripts
The Code Below Will Only work for R6

for i,v in pairs(script.Parent:GetChildren()) do
v.Touched:Connect(function(hit)
if hit.Name == "LeftArm" or hit.Name == "RightArm" then return end
hit.Color = Color3.fromRGB(0,146,0)
end
end)
end

It doesnt seem to be working. there was a error but i fixed it but it still wont work.

oops can you try again?
char limit

this script will change the limb that touches the parent of the script.

script.Parent.Touched:Connect(function(obj)
	if obj.Parent:FindFirstChild("Humanoid") and obj.Parent:FindFirstChild("Humanoid").Health > 0 then -- checks if there is a humanoid in the object's parent. and also checks if their alive
		local player = obj.Parent
		local damage
		local color = Color3.fromRGB(0,146,0) -- the color that the limb is gonna change to
		if obj.Name == "Head" then -- checks if the part hit the head
			damage = 56 -- optional. Chooses the amount if it hits this limb
			obj.Color = color
		
		elseif obj.Name == "Left Arm" or "Right Arm" or "Right Leg" or "Left Leg" then -- checks if the part hit the left leg, right leg, left arm or right arm
			damage = 15 -- optional. Chooses the amount if it hits this limb
			obj.Color = color
		elseif obj.Name == "Torso" then -- checks if the part hit the torso
			damage = 35 -- optional. Chooses the amount if it hits this limb
			obj.Color = color
		end
		player.Humanoid.Health = player.Humanoid.Health - damage -- Optional. Deals damage to the player
	end
end)

hope it helped. Just put the script inside of a part or the handle of a tool and then it will work

You made a typo

script.Parent.Touched:Connect(function(obj)
	if obj.Parent:FindFirstChild("Humanoid") and obj.Parent:FindFirstChild("Humanoid").Health > 0 then -- checks if there is a humanoid in the object's parent. and also checks if their alive
		local player = obj.Parent
		local damage
		local color = Color3.fromRGB(0,146,0) -- the color that the limb is gonna change to
		if obj.Name == "Head" then -- checks if the part hit the head
			damage = 56 -- optional. Chooses the amount if it hits this limb
			obj.Color = color
		
		elseif obj.Name == "Left Arm" or "Right Arm" or "Right Leg" or "Left Leg" then -- checks if the part hit the left leg, right leg, left arm or right arm
			damage = 15 -- optional. Chooses the amount if it hits this limb
			obj.Color = color
		elseif obj.Name == "Torso" then -- checks if the part hit the torso
			damage = 35 -- optional. Chooses the amount if it hits this limb
			obj.Color = color
		end
		player.Humanoid.Health = player.Humanoid.Health - damage -- Optional. Deals damage to the player
	end
end)

You mispelled “Left Arm”.