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

How to identify player is still touching a part despite lack of movement?

I created the following script:

script.Parent.Transparency = 1
script.Parent.CanCollide = true

function touch(plr)
	print("touched")
	wait(0.5)
	script.Parent.CanCollide = false
end

script.Parent.Touched:connect(touch)

I want to revert the CanCollide property for the parent back to true, but only when the player is no longer touching the parent. How can I do this? Apparently, the game identifies the player as no longer touching when they are not moving (even though they are still touching).

I tried adding the TouchEnded event, and all it does is infinitely switch the CanCollide property between true and false at a fast pace.

1 comment

0

Use a boolean value. When the part is being touched, set the boolean to true, and when the part has left collision with the player then set it to false.

1 answer

✓ Accepted answer

Yeah, that kind of stuff annoys me too. A way to get around this is to check in a radius if something is nearby.

local VectorA = Vector3.new(2, 6, 3)
local VectorB = Vector3.new(3, 7, 4)

local Distance = (VectorA - VectorB).magnitude
-- From here you can detect if the distance meets certain requirements

if Distance < 5 then
	-- do stuff
end

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