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

How to fix print(hit) not printing hit (otherPart) in a Touched:Connect script?

Asked by 2 years ago

I know this is a really small and probably obvious question, but I haven't found a solution to this and this has happened more then once.

I am testing out a cassette player which detects when the cassette hits the Part. I made a simple script that connects Touched to a function which prints hit, hit.Parent, and hit.Parent.Parent then prints "END", in order to test what the script would call the cassette.

The issue is that the code doesn't output anything except "END". Both objects have CanCollide on, and the cassette is unanchored.

Is there any reason why the script isn't printing hit? And if so, can and how would I go about fixing it?

script.Parent.Touched:Connect(function(hit)
    print(hit)
    print(hit.Parent)
    print(hit.Parent.Parent)
    print("END")
end)
0
Is the cassette a meshPart or a Model? strangejmaster43 139 — 2y

1 answer

Log in to vote
0
Answered by
SuperPuiu 497 Moderation Voter
2 years ago

Hit is a reference to an instance, so you have to use Name

script.Parent.Touched:Connect(function(hit) 
print(hit.Name) 
print(hit.Parent.Name) 
print(hit.Parent.Parent.Name) 
print("END") 
end)
Ad

Answer this question