I’m not very good at scripting, and I want to know how to make a script for a killbrick that only kills NPCs.
check if the hitted character isnt a player
use Player.Name == hit.Parent.Name
No problem for that, it’s kind of simple:
Let’s go in order…
-
Insert a Part
-
Insert your NPC (my example is ‘NPC’)
-
Add a BoolValue into the model attribute and call it whatever you like (my example is ‘IsNPC’)
-
Add a script to the part
-
Insert the following code:
local NPC = workspace.NPC
script.Parent.Touched:Connect(function()
if NPC:GetAttribute(“IsNPC”) == true then
NPC.Humanoid.Health = -1
end
end)
- If everything goes well, only the NPC will get killed by it.
Now, I would recommend using tables to get more NPCs but since your new to scripting I would like you to try this!
Definitely a much better approach then the solution above, even better if we use NPC:HasTag(“NPC”)
to even more easily mass distribute these.
if im correct if anything at all including the npc touches this part, the npc gets hurt.
i made a better script which not only fixes that problem but also has a debuf for each npc that touches it.
local npcsDebuf = {}
local debufTime = 2
local healthLost = 1
script.Parent.Touched:Connect(function(part)
local ModelAncestor = part:FindFirstAncestorWhichIsA('Model')
if npcsDebuf[ModelAncestor] then return end
task.spawn(function()
npcsDebuf[ModelAncestor] = true
wait(debufTime)
npcsDebuf[ModelAncestor] = false
end)
local ModelHumanoid = ModelAncestor:FindFirstChildWhichIsA('Humanoid')
if not ModelHumanoid then return end
local IsPlayer = game:GetService('Players'):GetPlayerFromCharacter(ModelAncestor)
if IsPlayer then return end
ModelHumanoid['Health'] -= healthLost
end)
i didnt test this code so if theres a problem feel free to tell me