Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Why isn't the Touch Detection Detecting Parts?

Asked by 3 years ago

What I mean by "Touch Detection" is when something touches another thing. Say we have this script:

local Part = (Part)

Part.Touched:Connect(function(hit)

 print(hit)

end)

When a Humanoid touches the part, it prints the parts of the Humanoid. When another part touches it, that doesn't happen. Why? How do I fix it?

2 answers

Log in to vote
0
Answered by
commag 228 Moderation Voter
3 years ago

I've run the script myself and can confirm the programming itself is fine. That said, the .Touched event is only run when a collision occurs. If the objects seem to be touching but don't class as a collision, that's likely the issue you're experiencing. For example, creating a part and manipulating CFrames to make them overlap doesn't provide a collision, as both parts are anchored and immovable, however, throwing a tool which is not anchored on to the part will cause a collision. Put more simply, the event doesn't register the touching of anchored parts.

0
Thanks! I'll try it out SuperQmod 18 — 3y
0
It worked, sorry I didn't get back sooner. As soon as it worked I moved onto the next part of my game xD SuperQmod 18 — 3y
Ad
Log in to vote
0
Answered by 3 years ago

You got to make it detect if its a part when its touched so

script.Parent.Touched:Connect(function(hit)
    if hit.Parent:FindFirstChild("Part") then
        print(hit)
    end
end)
0
That wouldn't have helped because it wasn't detecting a collision in the first place. All you're doing is debugging, which is something I already did lol. That's why I know there's a problem SuperQmod 18 — 3y

Answer this question