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

CFramed parts don't TouchEvent?

Hello, I am here just to take out an dobut that seriously intrigates me.

It's about with pure CFrame. While I was adusting an ascensor, I noticed that the Module could not detect touches with GhostPlates, then it could not update the stage where it was, so it does not know where it should stop (result, it is going up and up and up until the space.)

But we are going to go back to the example.

#The Example

Let's imagine a simple example. I have two parts, one called Part1 and another called Part2:

http://i1241.photobucket.com/albums/gg505/dav1000999/RobloxScreenShot10172015_214725602.png

The Part1 is CanCollide and Part2 not. (Part1 is the ascensor floor and the Part2 is the GhostPlate I refered above.)

Part1 is going to move around (up and down) Part2 so it touches it multiple times. Both are Anchored.

To move the Part1, I have something like that:

while true do
	for i = 9.5, 3.5, -2/30 do
		script.Parent.CFrame = CFrame.new(script.Parent.Position.X, i, script.Parent.Position.Z)
		wait()
	end
	for i = 3.5, 9.5, 2/30 do
		script.Parent.CFrame = CFrame.new(script.Parent.Position.X, i, script.Parent.Position.Z)
		wait()
	end
end

Simple, right? It will move the part smoothly, so it will absolutely touch the Part2

Now ill script it in order to say something onTouch.

script.Parent.Touched:connect(function(h) -- when part is touched
	if h.Name == "Part2" then -- if the part is the Part2
		print("Touch. Touch. Touch.") -- then say this message.
	end
end)

coroutine.resume(coroutine.create(function() -- create a coroutine in order to keep the event and the loop running at the same time.
while true do -- CFraming script.
	for i = 9.5, 3.5, -2/30 do
		script.Parent.CFrame = CFrame.new(script.Parent.Position.X, i, script.Parent.Position.Z)
		wait()
	end
	for i = 3.5, 9.5, 2/30 do
		script.Parent.CFrame = CFrame.new(script.Parent.Position.X, i, script.Parent.Position.Z)
		wait()
	end
end
end))

#Result

Nothing in the output.

Does someone understand why?

6 comments

1

I don't understand why your touched event would not fire, but you might try detecting whenever Part1 and Part2's Y Coordinate are the same, then you'll know they're touching.

1

However, a difference of 0.000000001 studs can make the script result in fail. Or not. But ill try.

1

well, your suggestion worked, but ill assume as provisory until they "fix" that issue. Thanks anyway!

1

The reason they don't fire the event is because both parts are anchored. Touched events only fire when an un-anchored part touches another. There is also no reason to run the coroutine, everything runs before the loop starts, so it doesn't interrupt it. 

1

Anchored parts don't touch. They can intersect, though. See http://wiki.roblox.com/index.php?title=API:Class/BasePart/GetTouchingParts

0

GhostPlate (Part2) isnt CanCollide, so it would fail anyway.

1 answer

CFraming has objects go through others therefore not allowing the onTouched event, you could have it instead, stop when the Y Coordinates are the same on both parts.

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