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

When player leaves the part how do you make it Cancollide to true?

Asked by
Jo1nts 134
4 years ago

im trying to make a noclip script its working but when the character leaves the part how do I make the part can collided to true

1game.workspace.Pleasedonatefreeloot.Head.Touched:connect(function(hit)
2    hit.CanCollide = false
3    for i,v in pairs(hit:GetDescendants()) do
4        v.CanCollie = false
5    print(hit.Name.."Nocliped")
6end
7end)
0
just noticed on 4th line it says CanCollie instead of CanCollide jwklong 32 — 4y

1 answer

Log in to vote
1
Answered by 4 years ago
Edited by Ziffixture 4 years ago

You can do it by using TouchEnded:

01local function onTouched(hit)
02    hit.CanCollide = false
03    for i,v in pairs(hit:GetDescendants()) do
04        v.CanCollide = false
05        print(v.Name.."Nocliped")
06    end
07end
08 
09local function onTouchEnded(hit)
10    hit.CanCollide = true
11    for i,v in pairs(hit:GetDescendants()) do
12        v.CanCollide = true
13        print(v.Name.."Nocliped")
14    end
15end
16 
17workspace.Pleasedonatefreeloot.Head.Touched:Connect(OnTouched)
18workspace.Pleasedonatefreeloot.Head.TouchEnded:Connect(OnTouchEnded)
0
Keep in mind the ramifications of using `Touched` and `TouchEnded`. If you're walking on a block, for example, you're continuously beginning and ending contact with it, because your character's legs are lifting and lowering, thus firing both events over and over again. The same thing applies when you stand still because of Roblox idle animations. I recommend looking into Region3 or magnitude Gey4Jesus69 2705 — 4y
0
Furthermore, the lowercase "connect" method of an RBXScriptSignal has been deprecated. ROBLOX utilizes TitleCase, please apply that convention. Ziffixture 6913 — 4y
Ad

Answer this question