Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

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

Title YouTube Video Code:

script.Parent.Touched:connect(function(hit)
print(hit.Name)
if hit.Name=="SynthPlay" then
script.Parent.Sound:Play()
end
end)

2 comments

0

Are you trying to get the player who touched it?

0

No, trying to get a Collidable part that slides across

3 answers

✓ Accepted answer

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.

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)

8 comments

0

Im trying to get whatever part it touches. This code is not a very good format.

0

Mine is more efficient

0

@Void_Frost How is your script deem more efficient if your script doesn't even work?

0

Joe, my script is easier, your script doesn't detect what is touched... only if it is touched.

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.

0

No, i say whenever it is touched, IF it is SnythPlay, it will play a sound

0

JoeRaptor, at least include ends, man.

0

That depends on how many ends you would need. @PersonaCole

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!

3 comments

0

Not Working

0

Is it in a server script.

0

Just updated my answer. Its working perfectly fine for me.

This discussion is preserved as it was. New answers, comments, and votes are closed.