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

How do you make it so when you touch a block,it plays music?

i don't know if this is about roblox lua though

1 answer

✓ Accepted answer

Well you have to use the Touched event and then use a method to make the sound play. Looks like low level research was gone into this one before asking but whatever.

local Sound = script.Parent:WaitForChild('Sound') -- Assuming sound is a child of your part and this script is also a child of the part
local Part = script.Parent

local SoundPlaying = false -- This is a boolean because we don't want the sound to play over and over every time we touch
Part.Touched:connect(function()
	if not SoundPlaying then
		SoundPlaying = true
		Sound:Play()
	end
end)

Sound.Ended:connect(function() -- This is to make it so when the sound ends we can touch the part again to make it play
	SoundPlaying = false
end)

1 comment

0

cool

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