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

How can I create an activated sound when using a tool and is it heard only by the user?

Hi everyone, I'm new and I need some help. First of all sorry for my English, because I'm Italian

I wanted to know how I could make a sound that is activated when using a tool (as if it were a sound effect) I managed to do this script.

wait ()
Player = game.Players.LocalPlayer
Character = Player.Character
Enabled = true
Mouse = Player: GetMouse ()

mouse.Button1Down: connect (function ()
script.Parent: play ()
end)

But the problem is that everyone can hear the sound!  I wanted to know how to make it feel to someone who uses it

Thank you so much to those who will help me!

3 comments

0

Is your game/project Filtering Enabled?

0

I do not know, how can I see it?

0

There is a property in Workspace. Also, later there will be an update that makes games be in experimental mode if not in FE (Filtering Enabled).

1 answer

✓ Accepted answer

You can use this. Also, I like my code compact and I dont like random spaces everywhere if it is not needed. I made a lot of comments on what I edited on your script to make it better. Also, dont make variables if your not going to use it.

local Player = game.Players.LocalPlayer
local Gui = Player.PlayerGui
local Mouse = Player:GetMouse ()
local Sound = 12345678 --Insert audio ID here.
local deb = false --A debounce to prevent the audio from playing multiple times at once, If you want it to, remove this part and the if statement.

--We dont need the Enabled variable or the Character variable, as we dont use it.

game:GetService('ContentProvider'):Preload(Sound) --This preloads the sound, so the first time they use it, there will be sound. If there is a error, it means that the Sound id is invalid, or it could not find it on Roblox for some reason.

local audio = Instance.new('Sound')
audio.SoundId = Sound
audio.Name = 'SoundEffect'
audio.Parent = Gui

mouse.Button1Down:connect(function()
	if not deb then
		deb = true
		Gui:WaitForChild('SoundEffect'):Play() --If you want it to play at a certain time, put the time in seconds in the first argument. Otherwise, leave it blank.
		wait(Gui.SoundEffect.TimeLength)
		deb = false
	end
end)

7 comments

0

Thanks a lot for your help, I copied the code and put it in a local script, then I followed all your steps and finally put the local script into my tool. When I clicked the sound did not start I checked if there was some error but nothing, I even checked if the audio id was wrong, but it works. Sorry for disturbing.

0

Its ok, just accept my answer.

0

how can I do? The audio does not start

0

are there any errors?

0

no

0

repaste the sound id

0

ok

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