When the ray hits something, it successfully prints the right hitpart name, but despite that, it doesn't do the right amount of damage that I tell it to. I notice that only the top 4 lines after "print(hitPart) works. The damage lines after that don't work, no matter how I order them. Well the humanoid does take damage, but it appears the the damage lines inherit the damage value from the lines before that, if that makes any sense. Like for the code below, if I shot a limb, then it will do 100 damage instead of 75. I've tried changing it to humanoid:TakeDamage(damage) but that doesn't work either. Am I doing something wrong?

	local Arms = "LeftUpperArm" or "LeftLowerArm" or "LeftHand" or "RightUpperArm" or "RightLowerArm" or "RightHand"
	local Legs = "LeftUpperLeg" or "LeftLowerLeg" or "LeftFoot" or "RightUpperLeg" or "RightLowerLeg" or "RightFoot"	
	function OnRayHit(cast, raycastResult, segmentVelocity, cosmeticBulletObject)
		if raycastResult ~= nil then
			local hitPart = raycastResult.Instance
			local hitPoint = raycastResult.Position
			local normal = raycastResult.Normal
			if hitPart ~= nil and hitPart.Parent ~= nil then -- Test if we hit something
				local humanoid = hitPart.Parent:FindFirstChildOfClass("Humanoid")
				if humanoid then
					local Creator_Tag = Instance.new("StringValue")
					Creator_Tag.Name = "Attacker"
					Creator_Tag.Value = script.Parent.Parent.Name
					Debris:AddItem(Creator_Tag, 2)
					Creator_Tag.Parent = humanoid
					print(hitPart)
					if hitPart.Name == "Head" then
						humanoid.Health = humanoid.Health - 120 -- Damage.
					elseif hitPart.Name == "UpperTorso" or "LowerTorso" or "HumanoidRootPart" then
						humanoid.Health = humanoid.Health - 100
					elseif hitPart.Name == Arms or Legs then
						humanoid.Health = humanoid.Health - 75
					end
				end
			end
		end
	end

1 comment

0

You need to use humanoid:TakeDamage(75) or something.

Also, don't forget that there is a possibility of it firing multiple times.