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

How do i make KillBrick that only kills NPC's?

Asked by 2 years ago

I have to make electricity fence for my game which kill every npc touching it. Im newbie to the roblox scripting, and every killbrick i make doesnt harm NPC's, but players.

Can anyone tell me how do i make this script? Or maybe even write it, if you want?

thanks.

5 answers

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

I'll try to give you an idea of how to go about this.

You can try adding a BoolValue named "isPlayer", or you can name it whatever you want into StarterCharacterScripts (You can insert a StringValue into Workspace first then reparent it into StarterCharacterScripts), make a regular script checking if the character that hits the fence has that value or not. If they don't have it, then they will be identified as an NPC, then you can kill it.

It would look like something like this:

script.Parent.Touched:Connect(function(hit)
    local human = hit.Parent.Humanoid

    if not hit.Parent:FindFirstChild(valuename) then -- If it didn't found the val
        -- rest of the code goes here
    end
end)
0
I am looking for any script/idea that can kill NPC's, because none of my scripts can harm any of them. The idea you have written will identify if the player is a NPC, or not, but will not kill it. However, thanks for this idea, it might be helpful later. Dawnymurzyn 7 — 2y
0
You need to make rest of the code.. RunkerSecurity 6 — 2y
Ad
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

First of all, name all of your NPC's humanoids to something other than 'Humanoid'.

Now, make a normal kill script but instead of checking if it is a player, check if the Humanoid in the player exists + is called whatever you called your NPCs' humanoids.

Example: Let's say all your NPC's humanoids were called 'NPCBot'.

For the kill brick script if it was inside the brick, you would do the following:

local killbrick = script.Parent -- Get the killbrick

killbrick.Touched:Connect(function(hit) -- See if it gets touched and connect a function
local hum = hit.Parent:FindFirstChild('NPCBot') -- Check to see if it is a NPC
    if hum then -- If it is a NPC then
        hum.Health = 0 -- Set the humanoid's health to 0, killing it
    end
end)

Hope this helps!

Log in to vote
0
Answered by 2 years ago
--add a BoolValue with False / True (does not matter) named identify to your NPC.

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("identify") and hit.Parent:FindFirstChild("Humanoid") then --Assuming all the parts are directly under the NPC. If not then put it into a while loop here, put the result in a variable and ascend keep its parent until it gets the “game.Workspace" parent or the NPC.
        hit.Parent.Humanoid.Health = 0 --this kills the NPC immediately, if you want to let him take damage then you can use the TakeDamage method.
    end
end)
Log in to vote
0
Answered by 2 years ago

Rename the NPC's Humanoid so that it will only damage that kind of humanoid. For example:

Normal Humanoid - Name of the Humanoid is "Humanoid" and the script sees the name Humanoid and runs the script

Renamed Humanoid - Name of the Humanoid is "EnemyHumanoid" and the script will only run the script if it detects the name "EnemyHumanoid"

0
Kind of copied my answer but ye PufferfishDev 49 — 2y
0
Kind of copied my answer but ye PufferfishDev 49 — 2y
Log in to vote
0
Answered by 2 years ago
Edited 2 years ago

To detect whether the given character isn't a player's character, you would just put this in a script:

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChildOfClass("Humanoid")then --checking if the thing touching the brick is a character
        if not game.Players:GetPlayerFromCharacter(hit.Parent)then --does the character belong to a player?
            local Humanoid = script.Parent:FindFirstChildOfClass("Humanoid")
            Humanoid.Health = 0
        end
    end
end)

You don't even need to change the humanoid's name!

Answer this question