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

Why doesn't the Touched event seem to be working?

Asked by 7 years ago

Title YouTube Video Code:

script.Parent.Touched:connect(function(hit)
print(hit.Name)
if hit.Name=="SynthPlay" then
script.Parent.Sound:Play()
end
end)
0
Are you trying to get the player who touched it? PyccknnXakep 1225 — 7y
0
No, trying to get a Collidable part that slides across Void_Frost 571 — 7y

3 answers

Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

I've seen the video. You've mispelled it.

You have the object in your workspace named "SnythPlay" instead of "SynthPlay". Be aware of spellings next time as it puts heavy problem/errors.

Ad
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

Try using this format from now on.

function onTouched(part)
    if part.Parent ~= nil then
        local h = part.Parent:findFirstChild(" Whatever object in workspace you want the script to detect on touch.")
         if h~=nil then
--Do stuff

script.Parent.Touched:connect(onTouched)
0
Im trying to get whatever part it touches. This code is not a very good format. Void_Frost 571 — 7y
0
Mine is more efficient Void_Frost 571 — 7y
0
@Void_Frost How is your script deem more efficient if your script doesn't even work? JoeRaptor 72 — 7y
0
Joe, my script is easier, your script doesn't detect what is touched... only if it is touched. Void_Frost 571 — 7y
View all comments (4 more)
0
@Void_Frost Then you have to mention that in your question. You expect the script to detect a part named "SynthPlay" to touch the object. That is what your script says. JoeRaptor 72 — 7y
0
No, i say whenever it is touched, IF it is SnythPlay, it will play a sound Void_Frost 571 — 7y
0
JoeRaptor, at least include ends, man. User#18043 95 — 7y
0
That depends on how many ends you would need. @PersonaCole JoeRaptor 72 — 7y
Log in to vote
0
Answered by 7 years ago
Edited 7 years ago

This should work for you:

script.Parent.Touched:Connect(function(hit) 
    print(hit)
    if hit.Name == "d" then
        print("It works!")
    end
    end)

This was tested. Please upvote and accept my answer if it helped!

0
Not Working Void_Frost 571 — 7y
0
Is it in a server script. PyccknnXakep 1225 — 7y
0
Just updated my answer. Its working perfectly fine for me. PyccknnXakep 1225 — 7y

Answer this question