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
✓ ANSWER ACCEPTED
How can i make a gun do damage to only npcs?
1 answer
✓ Accepted answer
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)
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
it's not a turret it's a shotgun
Oops, small mistake