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.
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!!
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!
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!