I need this script to damage the NPC but it's not working even though it works in every other part of the game and there are no errors but they are not taking damage pls help
function onTouched(hit) local holy = hit.Parent:FindFirstChild("holy") if (holy ~= nil) then holy.Health = holy.Health - 17500 end end script.Parent.Touched:Connect(onTouched)
Well...depending on the NPC, the NPC might have extra parts subbed under parts and trying to find the holy part.
This question isn't actually much in detail so trying my best and if you add more detail, I'll add more detail into this answer. But I can give some debugging tips of what to do if you get no output.
The first debugging tip is to print variables and see if they are nil or not, especially if you use an if statement to check.
Another debugging method also helps when ever you are trying to get a part's children and that is to use the for loop to see all the children and see if that part is even in it.
It is good to put as much print with variables in it for debugging, but remember to remove them when you found the error as depending on what you print, it could be a security issue in your game as it logs the game on the player as well. As I have use before.
Here is a link to how you can make a good question on here. https://scriptinghelpers.org/help/how-post-good-questions-answers
Here's something you can try:
script.Parent.Touched:Connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChild('holy') then local h = hit.Parent.holy h:TakeDamage(17500) end end)
If there are NPC's with different humanoid names, you could use a loop to find an object with the classname "Humanoid", so the name of it won't matter.
script.Parent.Touched:Connect(function(hit) if hit and hit.Parent and hit.Parent:FindFirstChildOfClass('Humanoid') then local Humanoid = nil for i,v in pairs(hit.Parent:GetChildren()) do if v.ClassName == 'Humanoid' then Humanoid = v end end if Humanoid ~= nil then Humanoid:TakeDamage(17500) end end end)