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

How do I make a Script that plays a Sound when touched?

I want to make a script for script builder that plays a sound when it's touched. If you didn't know, you can only add parts and stuff using Instances in SB. Can anyone help me?

1 answer

✓ Accepted answer

Simple.

local SoundID=176442243;--// The assetID for the sound you wish to play. The example sound is from Five Nights at Freddy's.

local DebounceTime,DebounceActive=3,false;--// The delay before the part can be touched again

local Part do
	Part=Instance.new('Part',workspace);--// Creates a new part and parents it to Workspace
	Part.Touched:connect(function()--// Whenever the part is touched, call this function
	
		if(DebounceActive)then return;end;--// Prevents the sound from rapidly playing
		DebounceActive=true;

		local Sound=Instance.new('Sound', Part);--// Creates a new sound in the part
		Sound.SoundId=('rbxassetid://'..SoundID);--// Sets SoundId, fixed from previous answer.
		Sound.Volume=1;--// The volume, can be changed.
		Sound.Pitch=1;--// The pitch, can be changed.
		Sound:play();
		
		delay(DebounceTime,function()--// After debounce cooldown, allows touching of part
			DebounceActive=false;
		end);

	end);
end;

My only regret is that Sound.TimeLength still does not work, so I cannot make the sound play out fully.

3 comments

0

It didn't work. It didn't have any errors, though.

0

Oh, sorry, I forgot to set the correct parameters for SoundId. I'll fix it.

0

Thanks!

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