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

How to make it so when a SPECIFIC part touches another part, it knows which one?

Asked by
Kitorari 266 Moderation Voter
8 years ago

How do you make it so when a part that doesn't DIRECTLY touch another part, it knows which one touched it?

Like here's sort of what I got, I have a block named Rainbow and another named Union9, I want rainbow to KNOW that specifically Union9 touched it, not Union8 or Union7.

I already know the first like for the event: if Script.Parent.touched (function(Hit) then After that I'm stalled.

3 answers

Log in to vote
1
Answered by 8 years ago

Ok, so just place a server script(normal script) under the rainbow and put the following code it should work if it doesn't, then comment down below but, this should be pretty basic.... Also if Union9 is just a part by itself that is touching the rainbow then this should work as in that union9 isn't under a model or anything if it's a Union Operation this should work....

script.Parent.Touched:connect(function(object)
local union9 = object.Parent:findFirstChild("Union9")
if union9 then --[[If statement saying if the part that touches the rainbow's name is "Union9" then it will do the following...--]]
--Code
end
end)
0
It still won't work. it might be because union9 is in a group called lane1? Kitorari 266 — 8y
0
Well is any part of the group except union9 touching the rainbow? KingLoneCat 2642 — 8y
0
Yes, Union1 to Union9. they are grouped as Lane1. Kitorari 266 — 8y
0
Ok I editted the script a bit a while ago and check it out now and when you write the rest of the code down make sure you adress the Union9 as union9 because I put a variable for it as you can see.... KingLoneCat 2642 — 8y
View all comments (4 more)
0
One again it didn't work. At this point I think it's just me doing something wrong. So yeah. Thank you for helping me! I just need to figure out what's wrong in it that I'm doing.. Kitorari 266 — 8y
0
I still want to see what you changed in the script do you mind showing me? And also make sure it's in a server script and it's under the object called "rainbow" KingLoneCat 2642 — 8y
0
It worked, I apologize X) The problem was rainbow was instead "Rainbow" and that messed everything up. Kitorari 266 — 8y
0
xD Well, I'm glad it works :D KingLoneCat 2642 — 8y
Ad
Log in to vote
0
Answered by 8 years ago

Well, there can be a few ways to do this, but this is the way I would personally do it

function onTouched()
    if hit.Parent.Name == "Union9" then
        ----------------What you want there
    else
    end
end)

script.Parent.onTouched:connect(onTouched)

Could be wrong, but give it a shot ;)

0
mmm not exactly. There is no "onTouched" event for a UnionOperation. Use the phrase "Touched" instead. LateralLace 297 — 8y
0
Sadly it didn't work KennySfromTitan. I don't know why. Kitorari 266 — 8y
0
I tried replacing ontouch with touched, but it still won't work. What is the line needed know that union9 touched it? Kitorari 266 — 8y
0
Did you change the onTouched in the connection line to Touched? (Case-sensitve) BlackJPI 2658 — 8y
0
Yes. yes I did. Kitorari 266 — 8y
Log in to vote
0
Answered by 8 years ago

I'm not necessarily sure if the touched event actually works on unions, but here's the code I'd use if it did. If you have more parts named Union9, then compare the object "hit", which is the object that touched the rainbow, to the instance Union9 instead of the names. Comment if you have any more trouble and try to include any errors.

--script inside of rainbow

script.Parent.Touched:connect(function(hit)--run the following code when the rainbow block is touched
    if string.lower(hit.Name) == "union9" then --If the part touched has this name, then run the following code. I used string.lower, because I didn't know if you named it with capitals or not, and the code is case-sensitive.
        print("I touched "..hit.Name)--print the union's name
    end
end)
0
Unions Inherit from BasePart, so they do indeed share the Touched funtionallity. BlackJPI 2658 — 8y

Answer this question