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

Enemy humanoid not taking damage?

Apologies for the terrible coding.

0 Errors, but the leg function seems incorrect. Any other better ways I can be doing this?

local uis = game:GetService("UserInputService")

local inCombat = false
local player = game.Players.LocalPlayer
local char = player.Character

local one = Instance.new("Animation")
one.AnimationId = "rbxassetid://1255742316"
local onePlayer = char.Humanoid:LoadAnimation(one)

uis.InputBegan:connect(function(input, gameProcessed)
	if input.KeyCode == Enum.KeyCode.G then
		if inCombat == false then inCombat = true
				onePlayer:Play()
							char.LeftLowerLeg.Touched:connect(function(hit)
								if inCombat == false then end
									if hit:FindFirstChild("Humanoid") 	~= nil then end
										if hit:FindFirstChild("Humanoid") then 
											local humanoid = hit:FindFirstChild("Humanoid")
												humanoid:TakeDamage(10)
										end
							end)
						wait(2)
							inCombat = false
				end
		end
end)**

1 answer

✓ Accepted answer

I'm assuming hit is returning a player's body part and not their player model. Try printing what is hitting along with this:

print(hit.Name)
hit.Parent:FindFirstChild("Humanoid")

Also your two checks for Humanoid are doing the same thing, and you could shorten your code by a small amount by defining humanoid before your "if then" statement. The following should do the trick.

local humanoid = hit.Parent:FindFirstChild("Humanoid")
	if humanoid then 
	humanoid:TakeDamage(10)
end         

1 comment

0

Thanks!

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