How to make a part disappear when hitting another (specific) part?

  1. What do you want to achieve? Keep it simple and clear!
    Hello again! I want to make a part disappear when it touches another specific part. They are both uncollidable.
  2. What is the issue? It doesn’t work, and doesn’t make any errors in output.

Here is the script I am using:

TweenService = game:GetService("TweenService")
local touched = script.Parent.Touched:Connect(function() end) touched:Disconnect()
local hitinfo = TweenInfo.new(
	0.4,
	Enum.EasingStyle.Cubic,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
local SoftBlock = script.Parent
for _, part in ipairs(SoftBlock:GetTouchingParts()) do
	if part.Name == "Explosion1" then -- change this
		local Disappear = TweenService:Create(SoftBlock, hitinfo, {Transparency = 1})
		SoftBlock.TextureID = nil
		task.wait(0.2)
		Disappear:Play()
		Disappear.Completed:Wait()
		SoftBlock.CanCollide = false
		task.wait(0.1)
		SoftBlock:Destroy()
	end

In this case, SoftBlock is a meshpart and Explosion1 is a part.
Any help is appreciated. Thanks!!

I’m pretty sure you need to loop it

You could also try:

SoftBlock.Touched:Connect(function(hit)
    if hit.Name == "Explosion1" then
		local Disappear = TweenService:Create(SoftBlock, hitinfo, {Transparency = 1})
		SoftBlock.TextureID = nil
		task.wait(0.2)
		Disappear:Play()
		Disappear.Completed:Wait()
		SoftBlock.CanCollide = false
		task.wait(0.1)
		SoftBlock:Destroy()
    end
end)
1 Like

I tried that earlier, it doesn’t work

Is it a local or server script?

1 Like

It’s a server script inside SoftBlock

Hmmmm, honestly, no idea. Hope someone can help you out

1 Like

replace for _, part in ipairs(SoftBlock:GetTouchingParts()) do with SoftBlock.Touched:Connect(function(part). and don’t forget to add a ) to the end statement that would be associated with the do block!

1 Like

Doesn’t work… Nothing in Output either

Delete the second line of your code.

1 Like

I deleted this, nothing happens eitherway

They can’t be detected if their collide is off, if you don’t want those 2 parts to be collided with the others, make them their own Collision Group

1 Like

Hello! First I’d like to start off by saying you were headed in the right direction and have the right idea!

The first thing you’ll need to fix is how the touched event is fired. I’m not sure if there is more to this script but as of now your Touched event is doing nothing, you are just simply storing it in an instance. You can fix this by removing the touched instance and leaving the Touched event out in the open.

TweenService = game:GetService("TweenService")

-- Remove the local touched = .....

local hitinfo = TweenInfo.new(
	0.4,
	Enum.EasingStyle.Cubic,
	Enum.EasingDirection.Out,
	0,
	false,
	0
)
-- You can also move this for loop into a function if you plan on reusing it
local function ExplosionEffect()
	local SoftBlock = script.Parent
	
	for _, part in ipairs(SoftBlock:GetTouchingParts()) do
		if part.Name == "Explosion1" then 
			local Disappear = TweenService:Create(SoftBlock, hitinfo, {Transparency = 1})
			SoftBlock.TextureID = nil -- This threw errors for me but its likely just something im missing from my place.
			task.wait(0.2)
			Disappear:Play()
			Disappear.Completed:Wait()
			SoftBlock.CanCollide = false
			task.wait(0.1)
			SoftBlock:Destroy()
		end
	end
	
end
-- Move the Touch event down here and assign the function to run when it fires.
script.Parent.Touched:Connect(ExplosionEffect) 

Well this works, you’ll likely need a way to move the “Explosion1” part using a tween service as I believe this part is likely anchored if you have set CanCollide to false.

Let me know if you are still having issues with this and I’ll try my best!

1 Like