I'm having trouble getting a sound to play when you click the part.
if game.Workspace:WaitForChild(game.Workspace.StatueClick.ClickDetector.MouseClick) then local Ambient2 = Instance.new("Sound") Ambient2.Parent = game.workspace Ambient2.SoundId = "rbxassetid://180919842" Ambient2:Play() Ambient2.Volume = 1 end end end
You are using an if statement when you should be calling an event. Change it to this:
local button = game.Workspace:WaitForChild('StatueClick').ClickDetector button.MouseClick:connect(function() if not game.Workspace:FindFirstChild('Ambient2') then local ambient2 = Instance.new('Sound', game.Workspace) ambient2.Name = 'Ambient2' ambient2.SoundId = 'rbxassetid://180919842' ambient2.Volume = 1 ambient2:Play() end end)
Hope this helps :)
It didn't work for some reason. What's the issue?
if game.Workspace:FindFirstChild("Sound") == nil then local Ambient = Instance.new("Sound") Ambient.Parent = game.workspace Ambient.SoundId = "rbxassetid://238895410" Ambient:Play() Ambient.Volume = 1 end end local button = game.Workspace:WaitForChild('StatueClick').ClickDetector button.MouseClick:connect(function() if not game.Workspace:FindFirstChild('Ambient2') then local ambient2 = Instance.new('Sound', game.Workspace) ambient2.Name = 'Ambient2' ambient2.SoundId = 'rbxassetid://180919842' ambient2.Volume = 1 ambient2:Play() end end)
Do you have a click detector? if you do, then you need the audio in the brick so the script can process the sound.
Your problem might just have been you were creating the sound and playing it under the same if statement, whether it exists or not. If the sound already existed, then the button wouldn't play. I went ahead and fixed that for you. I got this script to work in studio.
local button = game.Workspace:WaitForChild('StatueClick').ClickDetector if not game.Workspace:FindFirstChild("Ambient") then Ambient = Instance.new("Sound") Ambient.Name = "Ambient" Ambient.Parent = game.workspace Ambient.SoundId = "rbxassetid://238895410" Ambient.Volume = 1 end if not game.Workspace:FindFirstChild('Ambient2') then ambient2 = Instance.new('Sound', game.Workspace) ambient2.Name = 'Ambient2' ambient2.SoundId = 'rbxassetid://180919842' ambient2.Volume = 1 end button.MouseClick:connect(function() ambient2:Play() end)
Locked by MessorAdmin, woodengop, drew1017, and alphawolvess
This question has been locked to preserve its current state and prevent spam and unwanted comments and answers.
Why was this question closed?