of     1   

MilkyWay01
#63482564Sunday, February 26, 2012 4:57 PM GMT

In my game there is a yoshi morph and a gui that makes his tongue stick out. They both work. When someone gets hit by the tongue they freeze and that works too. But when the tongue isn't sticking out, the player can still get hit by it, even if it's CanCollide is false. The player doesn't hit the tongue like it would if its CanCollide was true. They walk through it but get affected by the script. I know CanCollide is false because in solo mode I have clicked the gui while looking at the tongues properties and seen when it is true and false. Here is the script that makes the tongue appear. It's in the gui: function color(mouse) script.Parent.Parent.Parent.Parent.Character.Chest.Tongue.Transparency = 0 script.Parent.Parent.Parent.Parent.Character.Chest.Tongue.CanCollide = true wait(3) script.Parent.Parent.Parent.Parent.Character.Chest.Tongue.Transparency = 1 script.Parent.Parent.Parent.Parent.Character.Chest.Tongue.CanCollide = false end script.Parent.MouseButton1Down:connect(color) So is there something wrong with my script or can a brick with a script in it really hit a person when its CanCollide is false.
thek00lkid
#63482685Sunday, February 26, 2012 4:59 PM GMT

CanCollide doesn't affect touch scripts. You'll need to use a debug variable.
MilkyWay01
#63482713Sunday, February 26, 2012 5:00 PM GMT

what's that
stravant
Forum Moderator
#63482898Sunday, February 26, 2012 5:02 PM GMT

The problem is in your assumption that it shouldn't collide because it's cancollide false. The touched event will fire even if the things in question are cancollide false, that only stops physical collisions, not Touched events. You can fix it by just ignoring touched events that happen when the part is cancollide false by adding an if statement to the handler.
MilkyWay01
#63483245Sunday, February 26, 2012 5:07 PM GMT

Here is the original script that freezes you: function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if human ~= nil then part.Parent:findFirstChild("Humanoid").WalkSpeed = 0 wait(5) part.Parent:findFirstChild("Humanoid").WalkSpeed = 10 end end script.Parent.Touched:connect(onTouch) And here is the new one I just made based on what you said: function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if human ~= nil and script.Parent.CanCollide = true then part.Parent:findFirstChild("Humanoid").WalkSpeed = 0 wait(5) part.Parent:findFirstChild("Humanoid").WalkSpeed = 10 end end script.Parent.Touched:connect(onTouch)
stravant
Forum Moderator
#63484744Sunday, February 26, 2012 5:30 PM GMT

You need to use `==` in your comparison of the CanCollide-ness of the part with true. See my post here describing why: http://www.roblox.com/Forum/ShowPost.aspx?PostID=63391669
nate890
#63485392Sunday, February 26, 2012 5:40 PM GMT

Or you can use (instead); CanCollide ^CanCollide==true not CanCollide ^CanCollide==(true and false or false and true) "Bro five! Wear this to let everyone know you think they deserve a high five."
stravant
Forum Moderator
#63485672Sunday, February 26, 2012 5:44 PM GMT

I think for beginners it's best to just ignore that and use the comparisons for clarity.
MilkyWay01
#63485803Sunday, February 26, 2012 5:46 PM GMT

so this would be right? function onTouch(part) local human = part.Parent:findFirstChild("Humanoid") if human ~= nil and script.Parent.CanCollide == true then part.Parent:findFirstChild("Humanoid").WalkSpeed = 0 wait(5) part.Parent:findFirstChild("Humanoid").WalkSpeed = 10 end end script.Parent.Touched:connect(onTouch)
stravant
Forum Moderator
#63485975Sunday, February 26, 2012 5:49 PM GMT

Yes. That would be good.
nate890
#63485992Sunday, February 26, 2012 5:50 PM GMT

If the hierarchy is correct, then yes. Also, use "FindFirstChild" instead of "findFirstChild" "Bro five! Wear this to let everyone know you think they deserve a high five."

    of     1