Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

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

Asked by 3 years ago

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

Log in to vote
1
Answered by
Cirillix 110
3 years ago
Edited 3 years ago
local Wall = script.Parent

Wall.Touched:Connect(function(hit)
      if hit.Name == "Ball" then
         hit:Destroy()
      end
end)
0
You forgot the "end" for the "if then" statement lol Omq_ItzJasmin 666 — 3y
0
lol Cirillix 110 — 3y
0
Wow I over thought things oof. raahatu 6 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

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!

Log in to vote
0
Answered by 3 years ago

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!

Log in to vote
0
Answered by 3 years ago

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)

Answer this question