Does 'destroy()` on it's own destroy it's parent?

I was reading some free model NPC script, and it had this on it’s own inside a function. Attached to a death event.

destroy()

Does this destroy the parent of the script? Or does this just destroy the script?

I always thought you needed to do

script:Destroy()

Or some other reference to the parent

Can you show the full script? I have a feeling destroy() is just a reference to a function within the script…

This code is attached to death event

	if DESTROY_ON_DEATH then
		delay(DEATH_DESTROY_DELAY, function()
			destroy()
		end)
	end
end

[/code]

Can I see the full code? I need to know whether or not it is a function.

Yes this code is inside a function


local function died()
	target = nil
	attacking = false
	newTarget = nil
	searchParts = nil
	searchingForTargets = false

	Zombie.heartbeatConnection:Disconnect()

	Zombie.humanoidRootPart.Anchored = true
	Zombie.deathAnimation:Play()

	wait(Zombie.deathAnimation.Length * 0.65)

	Zombie.deathAnimation:Stop()
	Zombie.humanoidRootPart.Anchored = false

	if RAGDOLL_ENABLED then
		Ragdoll(Zombie.instance, Zombie.humanoid)
	end

	if DESTROY_ON_DEATH then
		delay(DEATH_DESTROY_DELAY, function()
			destroy()
		end)
	end
end

Do you want the entire script? It’s like 500 lines

1 Like

destroy() must be a function inside the script.

1 Like

I want to see if destroy() is its own function, not if it is wrapped inside a function. Also, the full code is fine.

1 Like

You are correct, I didn’t know you could name a function that, figured it was a reserved keyword


local function destroy()
	Zombie:destroy()
end

That’s what I’ve been trying to say :rofl: (Ig i didn’t word it correctly)

1 Like

I thought you meant if the snippet was inside a function :stuck_out_tongue: