Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Npc can find other team but cant do damage?

Asked by 4 years ago

The script is inside of the npc. the npc is cloned in through a button, giving the npc a string value of the player who cloned the npc's team (player1 is on purple team, player1 clicks button and npc is cloned in, a string value is added with the value of "purple") . The npcs have follow scripts with target npcs of different teams. problem is the damage script either can't find the opposing npc's humanoid or another problem i don't know about

function dmg(hit)
    if hit ~= nil then
        local npcTeam = script.Parent.Team.Value
        local enemyTeam = hit.Parent.Team.Value
        local enemyHuman = hit.Parent:FindFirstChildOfClass("Humanoid")
        if npcTeam ~= enemyTeam then
            enemyHuman.Health = enemyHuman.Health - 10
        end


    end
end

hitbox.Touched:Connect(dmg)

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

Try this:

hitbox.Touched:connect(function(hit)
    local hum = hit.Parent:FindFirstChild('Humanoid')
    if hum ~= nil then
        local npcTeam = script.Parent.Team.Value
        local enemyTeam = hit.Parent.Team.Value
        if npcTeam ~= enemyTeam then
            hum:TakeDamage(10)
        end
    end
end)

I didn't test this out, so I have no idea if it would work but if it doesn't tell me any output errors if there are

0
no error, but no damage is being done WaterlooBuilder 4 — 4y
Ad

Answer this question