Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

How to code specific damage Script on a part?

Let's say a player touches a part and he touched it with it "Right Arm" or "Left Leg", how would I code something that detects that part of his/her body that it touches and gives a certain amount of damage?

1 comment

0

well im not really sure but wouldnt they have to have humanoids and then you just find it in there?

1 answer

✓ Accepted answer

Parent an IntValue or NumberValue in the part and subtract a value from it on collision.

--Script
game.Players.PlayerAdded:connect(function(ply)
	ply.CharacterAdded:connect(function(cha)
		local hum = cha:WaitForChild("Humanoid")
		local parts = {
			["Right Arm"] = 5,	--R6
			["Left Arm"] = 5,	
			["LeftLowerArm"] = 5,	--R15
			["LeftUpperArm"] = 5,
			["RightLowerArm"] = 5,
			["RightUpperArm"] = 5,
			["RightHand"] = 2,
			["LeftHand"] =2
		}
		for I,v in pairs(cha:GetChildren()) do
			if parts[v.Name] then
				local hp = Instance.new("IntValue",v)
				hp.Name = "Health"
				hp.Value = parts[v.Name]
			end
		end
	end)
end)

--Part that Touches character script

local damage = 5

script.Parent.Touched:connect(function(hit)
	local par = hit.Parent
	if par.ClassName == "Model" then
		local hp = hit:FindFirstChild("Health")
		if hp then
			hp.Value = hp.Value - damage
			if hp.Value <=0 then
				hit:Destroy()
			end
		end
	end
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.