Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How do you make an object disappear when it collides with another object?

Im Making Balls Drop From the sky and rolling down, but i need them to disaper after they hit the back wall. I cant find out how to do it.

(BTW Its in roblox Studios)

4 answers

local Wall = script.Parent

Wall.Touched:Connect(function(hit)
      if hit.Name == "Ball" then
         hit:Destroy()
      end
end)

3 comments

0

You forgot the "end" for the "if then" statement lol

0

lol

0

Wow I over thought things oof.

You would have to use the touched event to detect when the ball hits the back wall. You might need to use a module script but idk much about them. Here's the code:

local ball = script.Parent
	ball.Touched:Connect(function (hit)
 		if hit.Name == "Part name" then
			ball.Transparency == 1
		end
	end)

Note: Each ball needs to have this script in it for this to work. The ball will only disappear when hitting the floor so not if it hits anything else like a player. If your back wall is made up of multiple parts you need to change hit.Name to hit.Parent.Name

Hope this helps!

Ok So Here The Step:

1. Make A Floor

Make a floor that will destroy the ball, name it "Floor".

2. Make A Script

Make a Script and place it inside the "Floor".

Copy and Paste This Script:

local Floor = script.Parent

Floor.Touched:Connect(function(Hit) -- Detect If Something Touch The Floor
      if Hit.Name == "Balls" then -- Replace "Balls" with the name of your Falling Ball.
         Hit:Destroy() -- Destroy The Ball
      end
end)

Explanation

  1. local Floor = script.Parent is the Floor

  2. Floor.Touched will detect if something Touched the Floor, then will :Connect() it to a function

  3. if Hit.Name == "Balls" if the Hit name was "Balls", then...

  4. Hit:Destroy() It will :Destroy() the Hit

Hope It Helps!

This script detects when the ball touches another object and checks if it is the correct object.


local Part1 = game.Workspace.Part1 --Whatever the ball is
local Part2 = game.Workspace.Part2 --Whatever the ball is hitting

Part1.Touched:Connect(function(p) --Connected function
	
	if p == Part2 then --Check if its the right part
		
		--Code here
		
	end
	
end)

This discussion is preserved as it was. New answers, comments, and votes are closed.