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)
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
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…
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…
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.