Make audio when click button

Trying to make audio play when you click button via a script but its not working

local startb = script.Parent.Parent.StarterGui.LocalScript.Menu.TextButton
local song1 = Instance.new("Sound")
song1.SoundId = "rbxassetid://6927468309"
song1.Parent = script
startb.Activated:Connect(function()
wait(5)
song1:Play()
end)
1 Like
local startb = script.Parent.Parent.StarterGui.LocalScript.Menu.TextButton
local song1 = Instance.new("Sound")
song1.SoundId = "rbxassetid://6927468309"
song1.Parent = script
startb.MouseButtonClick1:Connect(function()
wait(5)
song1:Play()
end)

I have it attached to another script so it would not work with mousebutton1click

To access the player screen you must use PlayerGui:

local PlayerGui = game:GetService("Players").LocalPlayer:WaitForChild("PlayerGui")
local startb = PlayerGui.LocalScript.Menu.TextButton

local song1 = Instance.new("Sound",script)
song1.SoundId = "rbxassetid://6927468309"

startb.Activated:Connect(function()
	wait(5)
	song1:Play()
end)
1 Like

Doesnt seem to work and no errors codes I just dont hear the audio

1 Like

I have it all on a main handler

local camera = workspace.CurrentCamera

script.Parent.Enabled = true

wait(0.1)

game.Players.LocalPlayer.Character:FindFirstChild(“Humanoid”).WalkSpeed = 0

game.Players.LocalPlayer.Character:FindFirstChild(“Humanoid”).JumpHeight = 0

wait(3)

script.Parent.TextButton.Visible = true

script.Parent.TextButton.MouseButton1Click:Connect(function()

camera.CameraType = Enum.CameraType.Custom

script.Parent.Enabled = false

script.Sound.Playing = false

game.Players.LocalPlayer.PlayerGui.LocalScript:Destroy()

game.Players.LocalPlayer.Character:FindFirstChild(“Humanoid”).WalkSpeed = 16

end)

local music = script.Sound

local text = script.parent.TextLabel

if text.Visible == true then

music.Playing = true

end

player = game.Players.LocalPlayer

button = script.Parent.TextButton

local debounce = false

button.Activated:Connect(function()

if debounce == false then

debounce = true

player.Character:SetPrimaryPartCFrame(game.Workspace.Tel1.CFrame)

wait(1)

debounce = false

end

end)

local PlayerGui = game:GetService(“Players”).LocalPlayer:WaitForChild(“PlayerGui”)

local startb = PlayerGui.LocalScript.Menu.TextButton

local song1 = Instance.new(“Sound”,script)

song1.SoundId = “rbxassetid://6927468309”

startb.Activated:Connect(function()

wait(1)

song1:Play()

end)

1 Like

Try to add song1.Volume = 0.5 to the script sent by SOTR654.

where is this script located in, and is this a server script or a local script?

local script in startergui main handler

I already did try to set volume it just isnt playing

the code that you gave at the first post, is local?

it is local not server sideeee

Try this:

local startb = PlayerGui.LocalScript.Menu.TextButton
local song1 = Instance.new("Sound",script)
song1.SoundId = "rbxassetid://6927468309"

startb.Activated:Connect(function()
    print("Click")
    wait(1)
    song1:Play()
end)

If click is printed, add this line below like this:

song1.SoundId = "rbxassetid://6927468309"
if not song1.IsLoaded then 				song1.Loaded:Wait()					end

click was print int output but no sound

Question: Is “Menu” a ScreenGui?

Yes it goes a local script then the child is a menu

check if the sound instance is inside the script (or wherever the sound is parented) when button is clicked. If there is, check the properties of it if anything is nil (if the volume is low, or if the sound id is not there etc.)

Maybe you need to set the parent of the sound?

the sound is in the script not a pyshical sound object

Could you please check if a normal audio plays for you? (I mean putting a random audio in the workspace and ticking the “playing” property)
Maybe your Roblox volume is muted or idk.