How do i make a script that deletes itself after an npc dies?

Put script into Humanoid to avoid the dot operation,

--script is in Humanoid

local Npc = script.Parent.Parent
local Humanoid = script.Parent
Humanoid.Died:Connect(function()
task.wait(1)
Npc:Destroy()
end)
2 Likes

image
Whatā€™s wrong with the last line? itā€™s giving me this
image

1 Like

Put

end)

at the last line

2 Likes

image
still doesnt destroy for some reason
hold on i left the script disabled my bad

1 Like

Whats up with the task.wait() line?

1 Like

task wait is the new wait because wait is getting deprecated i think

2 Likes

Iā€™m gonna log into my pc and type out something you can try, Iā€™ll edit this comment in a minute

1 Like

yeah this still doesnt work even without the disabled script

2 Likes

Can you please show the code your using? Because if your using something else it might not work.

1 Like

Task.wait() waits until the next heartbeat, or in seconds if you define it with a number.

2 Likes

yeah, you want the noob3 script?

local NPC = workspace.testRig -- (Change "Test" to your NPC name)
local Humanoid = NPC:FindFirstChild("Humanoid")

for _, part in pairs(NPC:GetDescendants()) do
	if part:IsA("BasePart") and part:CanSetNetworkOwnership() then
		part:SetNetworkOwner(nil)
	end
end

task.wait(10)
while true do -- (Change the number to how long you want your npc to stop)
	for i=1, 55 do
		NPC.Humanoid:MoveTo(workspace["P1_" .. tostring(i)].Position)
		NPC.Humanoid.MoveToFinished:Wait()
	end
end

4 Likes

I find the highly excessive but, thanks for letting me know

2 Likes

Yes I wanted the noob3 script, since thats the one deleting the model

2 Likes

Everything should like this to delete the character
image
In this DeleteOnDeath Script should be this

local Humanoid = script.Parent
local Npc = Humanoid.Parent

Humanoid.Died:Connect(function()
	wait(1)
	Npc:Destroy() print(Npc.Name.." Has Died")
end)

You can even test this with a completely new character if it doesnā€™t work. Iā€™ve tested this in studio and it works fine

2 Likes

What do you use to make a new character? this doesnt work either

2 Likes

In Plugins"/image Click onimage and select R6 or R15 and just do Block Rig

2 Likes

Strangeā€¦ thats exactly what i doā€¦
R15 btw

3 Likes

Well it works fine for me im using R15 too, have you trying making a new character without the extra scripts in it?

2 Likes

Just tried, still nothing
Is it by chance the gun iā€™m using?
Rocket launcher by roblox doesnā€™t work either??

2 Likes

Maybe, Yes Im using a sword from roblox, does the gun your using acctuly do damage, like

Humanoid:TakeDamage(10)

and not

Humanoid.Health = Humanoid.Health - 10

?

1 Like