Touch event is not working at all

Hello everybody!

I’m working on a scene for my one of my games and I needed to use the touch event. Of course I quickly write it in a script and expect it to work. I test it, make the player go through an invisible wall that will detect when the player has touched it but nothing happens. Very confused but not surprised me goes to the forum and shamelessly copies a collision detection script. Overwrite the old script and well, nothing happened.

I have tried everything from making that wall not invisible and turn on collisions to crying until I die. Nothing worked.

That’s the code: I ended up using the raw unedited version because maybe I messed something up. And that didn’t work.

    local part = script.Parent
     
    local function onPartTouched(otherPart)
    	local partParent = otherPart.Parent
     
    	-- Look for a humanoid in the parent
    	local humanoid = partParent:FindFirstChildWhichIsA("Humanoid")
    	if humanoid then
    		-- Do something to the humanoid, like set its health to 0
    		humanoid.Health = 0
    	end
    end
     
    part.Touched:Connect(onPartTouched)

This is how it’s ordered.

Now hear me out, the very confusing thing is that I tried the same setup in another game and it worked. Well the problem with that is I can’t move to another map, because other games are braching off of this one and moving every one of those to a new game is too much brain damage for me to handle, so yeah. Maybe I had plugins that messed up the game, so I uninstalled all of them. Issue proceeds to proceed.

So I’m stuck on this one. Do you have any thoughts on what might be the problem.

create a new part and add it in and try it or make sure cantouch is set to true on the part
you could also use prints to debug if the touch event is even being fired…

I have tested it script works you have something else going on

Is the part’s cantouch property set to true?

1 Like

First, check if the part exists in-game. (On studio, open explorer and search for the part) Maybe it isn’t there because it doesn’t load, fell of the world. Etc…

I did that already. Not being detected.

No not now, but I tried it earlier.

You need to turn it on. A part can’t fire the .Touched event if this property is off

Try checking if all the player’s body parts cantouch properties are set to true, and also the part’s. Also check the output just in case.

1 Like

Nope, it’s very there. I tried putting the transparency up maybe that works. It didn’t, but I saw the part.

you tried a brand new part? or can you post the properties of the part here

Would you mind sending us a screenshot / gif of the part properties? Thanks in advance.

If you were to continue reading my message you would come to the realization that I did try that before.

I tried a new part, same deal.

also check your workspace properties the TouchesUseCollisionGroups maybe effecting it depending on if its set and if you use collisiongroups etc
https://gyazo.com/8ff66fd9f6426722c8901be6cd0e1808

Yes but, no matter what, we do need that property to be on. We may have already found a solution but we won’t know unless that property is on.

1 Like

My only conclusion is that probably an external source is affecting the script. Check if anything is giving the player’s humanoid more health, the script being disabled, any other script disabling or destroying the part…

There you go. I couldn’t fit the whole thing, I left out appearance


.

I haven’t checked if the script was disabled. Good idea, I’ll check now.

For debugging purposes print any part that touches and ignore the if statement for now. Does anything print? If so then we know that the problem is in the statement.

I know the issue now thanks to StormgamesYt7ip. I turned on collisions while testing, but that doesn’t register for some reason. Turning it on before testing has proven to be a solution. And of course thanks to everybody else for helping.

1 Like