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

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

Asked by
RAYAN1565 691 Moderation Voter
5 years ago
Edited 5 years ago

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.

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. T0XN 276 — 5y

1 answer

Log in to vote
2
Answered by
Optikk 499 Donator Moderation Voter
5 years ago

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
Ad

Answer this question