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

How can i detect if parts are touching?

Asked by 3 years ago

Okay, so i know how to detect if parts have touched, but i'm not sure how to detect if parts are touchING, i'm making the player's controller (that is if they are playing on controller) vibrate as long as a specific part is touching another anchored part, say, a block of ground, i used .Touched but i forgot that it only worked at the moment of the two parts touching, and didn't continue anymore (the vibrating is meant to be constant, so this doesn't work as it just stops after a small amount of time, i am unsure if i also have to detect when the parts stop touching to stop the vibration, so if anyone could help me out with that too then that'd be awesome

tl;dr: dont know how to detect constant contact between parts, help pls

2
you can have boolean variable which will be set to true when .Touched fires and .TouchEnded would set it back to false, this event fires when you stop touching part. imKirda 4491 — 3y

3 answers

Log in to vote
2
Answered by
3F1VE 257 Moderation Voter
3 years ago
local ps = game:GetService("Players")
ps.PlayerAdded:Connect(function(plr)
local val = Instance.new("BoolValue",plr.Character) -- set the parent to anything
local part = workspace.Map.VibaratePart
part.Touched:Connect(function(t)
if t.Parent == plr.Character then
val = true
part.TouchEnded:Connect(function()
val = false
end)
end)
end
end)
0
then add nifty script to detect when its true or false 3F1VE 257 — 3y
Ad
Log in to vote
1
Answered by 3 years ago

Use https://developer.roblox.com/en-us/api-reference/function/BasePart/GetTouchingParts. As documented there, if you have non-CanCollide parts involved, you may need to add TouchInterests, as explained here: https://devforum.roblox.com/t/simple-trick-to-make-gettouchingparts-work-with-non-cancollide-parts/177450

Log in to vote
0
Answered by 3 years ago

(answered by imKirda through comments, perfectly solves the issue i was having)

Answer this question