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

How can I check if an object touched another object?

Asked by 5 years ago

As you read from the title, I wanna know how do I check if an object touched another..

1 answer

Log in to vote
0
Answered by
Launderer 343 Moderation Voter
5 years ago

First you need to define your object you want to be touched. So say the script is inside of said object.

script.Parent

Now you need the Touched function.

script.Parent.Touched:Connect(function()
end)

Now to answer your specific part of the quest you get the touching object for the touched part by adding a variable inside the function parenthesis.

script.Parent.Touched:Connect(function(Hit)
end)

That would be where I put "Hit" inside the script. You can change that to anything but that's what I prefer. Then to see if it's touched by a specific object you make an if statement basically asking that same question.

script.Parent.Touched:Connect(function(Hit)
if Hit and if Hit == game.Workspace.Baseplate or Hit.Parent == game.Workspace.Baseplate then
print("Your desired object touched this object")
end
end)

In that script if the brick the script is inside of hits something named baseplate or the parent of what it hits is named baseplate then it will print Your desired object touched this object"

0
Also if anyone says I need to indent I say no. I am an avid hater of indenting, I find it makes your code look like sloppy pinetrees and I will not stand for it. Launderer 343 — 5y
0
You can be a hater of indenting as much as you want, but your code looks sloppy without it. Might as well write a paragraph about the mundane process of paint drying. Indentations also help others understand the code better and also makes editing a lot easier. Without the code indentations, it looks like you wrote a research paper about the complicated process of teleportation. KingLoneCat 2642 — 5y
0
IT worked... Had to make a bit of fixing... but thanks! mixgingengerina10 223 — 5y
0
enjoy your pinetree of ends then. Launderer 343 — 5y
Ad

Answer this question