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
3 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 — 3y

1 answer

Log in to vote
1
Answered by 3 years ago
Edited by Ziffixture 3 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 — 3y
0
Furthermore, the lowercase "connect" method of an RBXScriptSignal has been deprecated. ROBLOX utilizes TitleCase, please apply that convention. Ziffixture 6913 — 3y
Ad

Answer this question