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

How do I make this play a sound when the character clicks while holding a certain item?

local tool = script.Parent local sound = game.workspace.backup.GameToy.Sound tool.Activated:Connect(function() game.Workspace.Backup.GameToy.Sound:Play() end)

Here's what I have so far. Here's some context in case you're confused: GameToy is the tool I want to play a sound. "Backup" is a folder in the workplace where I keep the Gametoy.

2 comments

0

Would you mind putting it into a codeblock?

0

Try adding a wait() for however long the song is.

1 answer

So If You Want It To Do It For The Client Only Then Do This:

  • Make A Local Script
  • Put The Local Script Inside Of The Tool
  • Put This Inside Of The Local Script
local tool = script.Parent -- Put The Local Script Inside The Tool
local songid = 0 -- The Numbers In The Song
tool.Activated:Connect(function()
local sound = Instance.new("Sound")
sound.Parent = tool
sound.SoundId = "rbxassetid://"..songid
sound:Play()
wait(sound.TimeLength)
sound:remove()
end)
  • Change songid To The Numbers Of The Song (Not "rbxassetid://0"!)

If You Want it To Play On The Server Side Its A Bit Harder

  • Make A Local Script
  • Put The Local Script Inside Of The Tool
  • Put This Inside Of The Local Script
local tool = script.Parent -- Put The Local Script Inside The Tool
local songid = 0 -- The Numbers In The Song
tool.Activated:Connect(function()
game.ReplicatedStorage.SoundServer:FireServer(songid)
end)
  • Change songid To The Numbers Of The Song (Not "rbxassetid://0"!)
  • Make A Script -. Put The Script Inside Of ServerScriptService Or Workspace
  • Put This Inside Of The Script
game.ReplicatedStorage.SoundServer.OnServerEvent:Connect(function(player,songid)
local sound = Instance.new("Sound")
sound.Parent = workspace
sound.SoundId = "rbxassetid://"..songid
sound:Play()
wait(sound.TimeLength)
sound:remove() 
end)
  • Now Finally Put A Remote Event In Replicated Storage And Name It: SoundServer
  • Enjoy

If You Have Any problems Feel Free To Contact Me On Discord: Harry_TheKing1#2303

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