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

How to damage NPC enemies and get KOs for them?

Asked by
mrcare -5
6 years ago
Edited 6 years ago

I've completed the animation process of my punch tool [as seen below], but can't get around damaging NPC's only when clicking and figuring out how to get a KO on the leaderboard after killing them. Keep in mind I'm using a "handless" tool.

local plr = game.Players.LocalPlayer
local char = plr.Character or plr.CharacterAdded:wait()
local tool = script.Parent
local swingsound = tool:WaitForChild("Swing")


tool.Activated:connect(function()
    local choose = math.random(1,3)

    if choose == 1 then
        local swing1animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch1)
        swingsound:Play()
        swing1animation:Play()
    elseif choose == 2 then
        local swing2animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch2)
        swingsound:Play()
        swing2animation:Play()
    elseif choose == 3 then
        local swing3animation = script.Parent.Parent.Humanoid:LoadAnimation(script.Punch3)
        swingsound:Play()
        swing3animation:Play()
    end
end)

tool.Unequipped:connect(function()
    local hum = char:WaitForChild("Humanoid")
end)
0
First, explain more, second... your problem is damaging the NPC or increasing the amount of KO's in your Leaderboard? AIphanium 124 — 6y
0
The problem I'm having is that when I use the punching tool, I want it to damage the NPC only when I left click. And the other problem I'm having is that I have no idea how to increase the amount of KOs on the leaderboard after I [successfully] kill an NPC (and I have a KO counter script already implemented into the NPC which gives a KO if I kill the NPC with another weapon, such as a sword). mrcare -5 — 6y

1 answer

Log in to vote
0
Answered by
tobhyyy 26
6 years ago
Edited 6 years ago

To deal damage to a target humanoid you want to a touched event, then check if what you touched has a humanoid inside of it.

LeftHand.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(Number)
    end
end)

now to increase damage do

LeftHand.Touched:Connect(function(Hit)
    if Hit.Parent:FindFirstChild("Humanoid") then
        Hit.Parent:FindFirstChild("Humanoid"):TakeDamage(Number)
            if Hit.Parent:FindFirstChild("Humanoid").Health <= 0 then
                Player.leaderstats.KOS.Value = Player.leaderstats.KOS.Value + 1
        end
    end
end)

sorry if the code is slightly off, im writing on mobile

0
Problem: Every time the left arm hits a part of a dead NPC it gives me a KO. So if I killed one NPC, but the torso, left arm, and right arm of the NPC hit my left arm, I'd get 3 KOs instead of one. mrcare -5 — 6y
0
add a debounce tobhyyy 26 — 6y
0
Awesome! Thanks man. mrcare -5 — 6y
0
Oops. another problem. Whenever I play in-game the leftArm connect function conflicts with something so I can't damage the NPCs. mrcare -5 — 6y
Ad

Answer this question