Hello Developers! I need help with detecting if a humanoid belongs to a player or NPC. I need this so that my gun can only attack NPC’s and not Players.
Here is the part of my script which does damage:
local function _defaultDamageCallback(system, target, amount, damageType, dealer, hitInfo, damageData)
if target:IsA("Humanoid") then
target:TakeDamage(amount)
end
end
What edit do I have to make so that it can only attack NPCs?
You could check if game.Players:FindFirstChild(targetName) or you could store all of your NPCs in a folder in workspace and check if the humanoid’s parent is in that folder.
You can use Players:GetPlayerFromCharacter and give it the parent of the humanoid. If it returns a player, it is a humanoid of a player’s character (Or do what @NicholasY4815 said).