#{SOLVED} I dont want this to damage other NPCS

1 messages · Page 1 of 1 (latest)

deep vapor
#

local npc = script.Parent
local human = script.Parent.Humanoid
local hrp = npc.HumanoidRootPart
local runservice = game:GetService("RunService")
local Players = game:GetService("Players")
debounce = false
local damageAmount = 10

for _, child in pairs(npc:GetChildren()) do
print(child)
if child:IsA("BasePart") then
child.Touched:Connect(function(hit)

        if debounce then return end
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        if humanoid then
            humanoid:TakeDamage(damageAmount)
            local Animation = script.Animation
            local Anim = human:LoadAnimation(Animation)
            Anim:Play()
            
            debounce = true
            wait(4)
            debounce = false
            
            
        else
            
        end
    end)
end

end

cunning ridge
#

You can check if its a player by doing: game.Players:GetPlayerFromCharacter(model)

deep vapor
#

I just starting scripting but I tried this and its not working i'm not sure how I should fix this heres the script

#

local npc = script.Parent
local human = script.Parent.Humanoid
local hrp = npc.HumanoidRootPart
local runservice = game:GetService("RunService")
local Players = game:GetService("Players")
debounce = false
local damageAmount = 10

for _, child in pairs(npc:GetChildren()) do
print(child)
if child:IsA("BasePart") then
child.Touched:Connect(function(hit)

        if debounce then return end
        local humanoid = hit.Parent:FindFirstChild("Humanoid")
        local player2 = game.Players:GetPlayerFromCharacter(hit.Parent)
        if humanoid and not player2 then
            humanoid:TakeDamage(damageAmount)
            local Animation = script.Animation
            local Anim = human:LoadAnimation(Animation)
            Anim:Play()
            
            debounce = true
            wait(4)
            debounce = false
            
            
        else
            
        end
    end)
end

end

cunning ridge
#

If game.Players:GetplayerFromCharacter(hit.parent) then

deep vapor
#

got it

#

i closed the post