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

How to make my npc's body parts remove on death while keeping respawn?

Asked by 5 years ago

So when my npc's die their body parts scatter how would I remove this? Main script for animations/movement is here. https://pastebin.com/Awe5RYGm The script is so big it cant be posted but also this is a follow script so when it detects players it will follow the player if you need or want it.

01function findNearestPlayer(Position)
02    wait(0.3)
03    local List = game.Workspace:GetChildren() --it's :GetChildren() not :Children()
04    local Target --Just need this
05    local Distance = 20
06 
07    for i, v in pairs(List) do --loops through all entries in List
08        local humanoid = v:FindFirstChild("Humanoid") --Checks for a humanoid
09        local hrp = v:FindFirstChild("HumanoidRootPart") --Checks for a RootPart
10 
11        if humanoid and hrp and v ~= script.Parent then --If it has both and v is not the script's parent
12            local dist = (Position - hrp.Position).Magnitude
13            if dist <= Distance and humanoid.Health > 0 then
14                local plr = game.Players:GetPlayerFromCharacter(v)
15                if plr then --If it's a player
View all 30 lines...

I also want to keep the ability to respawn but if I put this script in,

1local humanoid = script.Parent:FindFirstChild()
2if humanoid  == nil then
3    warn("Humanoid is nil!")
4end
5humanoid.Died:Connect(function()
6    local Char = script.Parent
7    Char:Destroy()
8 
9end)

I wouldnt be able to make the npc respawn. I heard if keep a copy in server storage and copy that and the place the npc respawns I could keep both? I need assistance

0
the bottom script is the script for deleting the npc after death so no body parts everywhere MrMeeper9 39 — 5y
0
Yes if you put an npc in server storage and clone it you could just destroy it. Have a script in ServerScriptService check for the npc in the inventory and replace it with npc:Clone() if it's not there. Narunzo 172 — 5y

1 answer

Log in to vote
1
Answered by 5 years ago

try doing something along the lines of this:

1local bodyparts = script.Parent:GetChildrenOfClass("Part")
2bodyparts:Destroy()
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
View all comments (10 more)
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
0
i just realized ScriptsALot 91 — 5y
Ad

Answer this question