You HAVE to check for the humanoid BEFORE ANYTHING ELSE.
1 | script.Parent.Touched:connect( function () |
2 | if script.Parent:FindFirstChild( "Humanoid" ) then |
3 | script.Parent.CanCollide = false |
4 | elseif not script.Parent:FindFirstChild( "Humanoid" ) then |
5 | script.Parent.CanCollide = true |
you didnt check for it. you just sent an empty request. it finds it but doesnt know what to do with that info
EDIT: So it sent the empty request and moved on to setting it to false, then checking for the other condition. (Note: elseif is better practice)
REEDIT:
01 | script.Parent.CanCollide = true |
03 | script.Parent.Touched:connect( function (hit) |
04 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
05 | script.Parent.CanCollide = false |
09 | script.Parent.TouchEnded:connect( function (hit) |
10 | if hit.Parent:FindFirstChild( "Humanoid" ) then |
11 | script.Parent.CanCollide = true |