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

How can i make a gun do damage to only npcs?

Asked by 3 years ago

I want to make my trench gun do damage to an enemy i put into my game but i shoot the enemy and it does no damage i am new to scripting since i want to make a game how ever i also want my gun to do damage to other npcs not just one (no not area damage or that kind of thing) like my gun does damage to zombie right? now if i add another name will it do damage to skeleton? those aren't the enemies i added fun fact i added peppa pig XD i want my gun to do damage to it

1 answer

Log in to vote
0
Answered by 3 years ago

This script should be inside the bullet that should be getting cloned from the turret.

local Bullet = script.Parent
local debounce = false
local Damage = 10

Bullet.Touched:Connect(function(Hit) -- Runs when it touched something
    if not debounce then
        local Humanoid = Hit.Parent:FindFirstChild("Humanoid") -- Check if it hit a character
        if Humanoid then
            local Player = game.Players:GetPlayerFromCharacter(Humanoid.Parent)
            if not Player then -- Make sure its not a player
                debounce = true -- Cant hit multiple npcs at once
                Humanoid:TakeDamage(Damage)
                Bullet:Destroy()
            end
        end
    end
end)
0
it's not a turret it's a shotgun dylancrazy88 20 — 3y
0
Oops, small mistake MikkelCircled 42 — 3y
Ad

Answer this question