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

game.workspace.Pleasedonatefreeloot.Head.Touched:connect(function(hit)
    hit.CanCollide = false
    for i,v in pairs(hit:GetDescendants()) do
        v.CanCollie = false
    print(hit.Name.."Nocliped")
end
end)

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:

local function onTouched(hit)
    hit.CanCollide = false
    for i,v in pairs(hit:GetDescendants()) do
        v.CanCollide = false
        print(v.Name.."Nocliped")
    end
end

local function onTouchEnded(hit)
    hit.CanCollide = true
    for i,v in pairs(hit:GetDescendants()) do
        v.CanCollide = true
        print(v.Name.."Nocliped")
    end
end

workspace.Pleasedonatefreeloot.Head.Touched:Connect(OnTouched)
workspace.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