Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

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)

1 comment

0

just noticed on 4th line it says CanCollie instead of CanCollide

1 answer

✓ Accepted answer

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)

2 comments

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

0

Furthermore, the lowercase "connect" method of an RBXScriptSignal has been deprecated. ROBLOX utilizes TitleCase, please apply that convention.

This discussion is preserved as it was. New answers, comments, and votes are closed.