So basically im trying to make a part damage a enemy when touched (not a player), and when I test them on them it doesn’t do damage. (Theres no errors either)
Script:
The rest of the script won’t run because you’re telling the script to stop executing that code block if a part’s that is a descendant of a player is found, if you’re not looking to damage any players why bother even checking if the part that is touched is a descendant of a player? Simply remove that line and only check if that part’s descendant is the enemy’s .
I think you’re really overcomplicating this, a lot of unnecessary iterations for what!
if game:GetService("Players"):GetPlayerFromCharacter(Hit.Parent) == nil then
local EnemyHumanoid = Hit.Parent:FindFirstChild("Humanoid")
if EnemyHumanoid and EnemyHumanoid.Health > 0 then
EnemyHumanoid:TakeDamage(20)
end
end
It’s important that you make sure the enemy still has an existing humanoid incase it dies in between of damaging / killing it or else the script will not run after for the rest.
I don’t get how it is the problem though, since in my other weapon I use the same script and it works perfectly fine, the only difference being the script isn’t in the damage part, its working from a folder
@abclike123ye Did you forget to change canHit back to true? Cuz it seems like you didn’t state there anywhere in the code thus potentially stopping your whole code with “if canHit == false”.
Plus yeah if you want to check whether a humanoid was a player or not you can do Squally’s way