Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 4 years ago

Please encode Lua code in the Lua block code tag (look for the Lua icon in the editor).

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.

0
Would you mind putting it into a codeblock? tictac67 96 — 4y
0
Try adding a wait() for however long the song is. AntiWorldliness 868 — 4y

1 answer

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

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

Ad

Answer this question