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

How can I check if an object touched another object?

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

1 answer

✓ Accepted answer

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"

4 comments

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.

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.

0

IT worked... Had to make a bit of fixing... but thanks!

0

enjoy your pinetree of ends then.

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