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.
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)
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 ;)
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)