Hello. I'm trying to make a script where it only works if it's touching another specific object. The current script I use is
local function onTouch(hit)
if (hit.Parent.Parent.Parent) then
print(hit)
script.Parent.Parent.Object1.AlignPosition.Enabled = true
wait(1)
script.Parent.Parent.Object1.AlignPosition.Enabled = false
end
end
script.Parent.Touched:connect(onTouch)
I've tried doing
local function onTouch(hit)
if (hit.parent.findFirstChild("Object2")) then
print(hit)
script.Parent.Parent.Object1.AlignPosition.Enabled = true
wait(1)
script.Parent.Parent.Object1.AlignPosition.Enabled = false
end
end
script.Parent.Touched:connect(onTouch)
but it doesn't work. When I use the first script, anything touching Object1 activates AlignPosition, but I only want it that when it touches Object2 it activates AlignPosition. Any help is appreciated. Thanks!

3 comments
Yep, it works. Thank you so much!
np
btw, your way could also work but you used "." and not this ":"