Delete part right when its touched

  1. What do you want to achieve? Keep it simple and clear!
    Make the FireTrail delete immediately when touched.

  2. What is the issue? Include screenshots / videos if possible!
    It deletes the Part with delay and I want it to delete right when it touched without delay.

  3. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    I couldn’t find anything to fix it.

FireTrailClone.Touched:Connect(function(TouchedObj)
		if TouchedObj:IsDescendantOf(Player.Character) then return end
		
		if TouchedObj.Parent:FindFirstChild("Humanoid") and TouchedObj.Parent.Name ~= Player.Name then
			FireTrailClone:Destroy()
			TouchedObj.Parent.Humanoid:TakeDamage(100)
			
			local Fire = Instance.new("Fire")
			Fire.Heat = 0
			Fire.Size = 125
			Fire.Parent = TouchedObj.Parent.HumanoidRootPart
			wait(1)
			Fire.Size = 15
		else
			FireTrailClone:Destroy()
			print(TouchedObj)
		end
	end)

Here is how it looks.
https://gyazo.com/793d07f9a3aa2a92201428124d422d70

1 Like

In terms of performance, I would check the View > Performance window and check the script’s performance time. Use Debris:AddItem() as an alternative but I don’t think is any better than Instance:Destroy().

local FireTrailClone = workspace.FireTrailClone
local Debris = game:GetService("Debris")

Debris:AddItem(FireTrailClone, 0.1)

Disposing of unneeded objects is important, since unnecessary objects and connections in a place use up memory (this is called a memory leak ) which can lead to serious performance issues over time.
You can also try setting the object to nil:

local Fire = Instance.new("FireTrail")
Fire = nil

Hope this helps, it is just my interpretation of the issue!

1 Like

in Performance it says that the AverageGcIn… is 16-17 and the AverageGcTime 0.1000.

I tried it with Debris but it deletes with a little more delay.

The hit detection is happening server-side, yes? The delay you are seeing would then be due to latency: the client has not received the information yet that the part has been destroyed; however, because your client is the network owner of the part, it is simulating physics on its own end, as well, resulting in the part bouncing around while it waits for the :Destroy() to replicate.

To alleviate this, you will need to run hit detection on the client’s end as well whose sole purpose is to destroy the object when it hits something.

2 Likes

Thanks! It’s working good now.