I am trying to script two objects colliding together and causing a huge explosion. I currently have the objects tweened and they meet however, I can’t seem to figure out how I would write the code for the objects to collide. Should I use a remote event? My thought process through this collision is that:
local part1 = script.Parent.Part1
local part2 = script.Parent.Part2
if(part1.Touched == part2) then
--make an explosion happen and the parts disappear
end
How would I make this happen because I know that the touched statement doesn’t work in the fashion that the code that I wrote above does.
How would the explosion be made? From what I’ve seen in API reference, I don’t see anything that could make the part explode. Would I just make a separate event that is run once the parts collide?
If you want to use a roblox explosion then you could create a new explosion instance. Here would be some code that makes part1 explode when it collides with part2:
part1.Touched:Connect(function(hitPart)
if hitPart == part2 then
local explosion = Instance.new("Explosion")
explosion.Position = part1.Position
explosion.Parent = workspace -- detonates the explosion
explosion.BlastPressure = 500000
explosion.BlastRadius = 10
part1:Destroy() -- make part1 "vanish"
part2:Destroy() -- make part2 "vanish"
end
end)
Also, touched is not the best option, especially if your parts are anchored, perhaps use Region3’s or Magnitude checks. If touched isn’t working properly for you, you can USS what I have suggested