So I’m trying to make one of my play buttons play a sound when it’s clicked.
It works but the thing is I already have a script for my play button that has a destroy function for the main menu when clicked the Play button.
I don’t know if I’m right but it might be canceling out the sound effect script before it can even play it.
Yeah the script does work but my issue is that either the sound won’t play and my play button works perfectly, or the sound works but the play button scripts breaks. (The script I’m referring to is the second screenshot.) Any idea on how I can fix this solution? Sorry for the misunderstanding!
You want a sound effect to play when a button is clicked
You want to the button to do something
This might be my lack of insight on GUI in general, but I am a little bit confused on the need to destroy the main menu and not just use .Visible = false or .Enabled = false instead.
Here is a script with both functions, which seems to work as intended for me:
local button = script.Parent
local sound = script:WaitForChild("Wipe Out")
local FrameBack = button.Parent:WaitForChild("Frame")
button.MouseButton1Click:Connect(function()
sound:Play()
FrameBack:WaitForChild("FrameChanged").Visible = not FrameBack:WaitForChild("FrameChanged").Visible
end)
Would you say this would be an acceptable, alternate way to go bout this? I feel like this might be the easier way, as when it is false, it would feel the same to the normal player as if it were destroyed. Additionally, you can always make it visible later! I hope this helps!
If you look at the first lines of the Sound documentation you’ll see that sounds have to be a child of a Part or Attachment.
If it’s in the workspace then it’ll play everywhere.
Yeah that was one of my assumptions but thanks for clarifying that! So I have a script that is playing a camera from a part right, then there’s a script for my play button that destroys the entire main menu when clicked thus making the player being able to play the game. The issue is that whenever I try to make a sound play when that button is clicked it doesn’t work (probably assuming from the destroy function as listed in the second screenshot of code) I’ve been trying to find a way to balance it and have a way where both codes work if it’s possible.
I don’t think this would work since it’s projecting from a part as a camera than being an actual frame.
Here’s a better explanation if you’re still confused.
So I have a script that is playing a camera from a part right, then there’s a script for my play button that destroys the entire main menu when clicked thus making the player being able to play the game. The issue is that whenever I try to make a sound play when that button is clicked it doesn’t work (probably assuming from the destroy function as listed in the second screenshot of code) I’ve been trying to find a way to balance it and have a way where both codes work if it’s possible.
You really only need 1 function with the MouseButton1Click to do all of that.
When it fires, play the sound first, use a task.wait(1 or however many seconds you’d like), then use the section of code from inside your function Play() to change the camera type and destroy the script.
Also, wait is deprecated so use task.wait'. (.001) is smaller than the time it takes for 1 frame to pass, which is about .03 seconds so just use task.wait()`.
The issue is that the sound is located inside inside Play_btn with the sound effect local script. And when you destroy the button, it destroys everything inside it including the sound and the sound effect local script. So its not possible for the sound to be played becouse its deleted.
To fix the issue you can change the sound effect and the Sound itself parent somewhere else where its not getting deleted.
Yeah you are right, my output keeps saying Infinite yield possible on’Players.Straw_26.PlayerGui.MainMenu.PlayButton:WaitForChild(“Click”)’
which should mean that click doesn’t exist
Is it something with my code?
Players.Straw_26.PlayerGui.MainMenu.PlayButton:WaitForChild(“Click”)
Doesn’t this mean your script is searching for “Click” in the Players service version of Straw_26, not the workspace version of Straw_26?