You need to make sure you are using a LocalScript
and make sure you're placing it inside the button which might be your issue.
But let me help you understand the script.
What I would do is first define everything so with the sound.
1 | local Sound = game.ReplicatedStorage:FindFirstChild( "Sound" ) |
And make sure Sound
is the name of your sound. (I recommend naming it to something different because, if you have multiple in ReplicatedStorage
named Sound
then it would confuse the script.)
For example if it was named OpenSound
I wouid change this to.
1 | local Sound = game.ReplicatedStorage:FindFirstChild( "OpenSound" ) |
Therefore if there is only one sound in there named OpenSound
it wont get confused.
Also make sure that in the ReplicatedStorage
you have a Sound
in there at all, although this isn't even required so you remove this portion of the script.
The part where you find the open this has the Open
placed inside of the parent's parent of the button and the parent
of the Frame
1 | local Open = script.Parent.Parent.Parent:FindFirstChild( "Open" ) |
So for example In the StarterGui
it has a child which is the ScreenGui
and inside of that is the frame that you want being open and closed and inside of that is the Button. So if it's set up like this then your Open
is a child of the StarterGui
right next to the ScreenGui
. But let's say that your frame that you want open and closed is inside of another frame then your Open
needs to be in the ScreenGui
with the other frame. I don't exactly recommend this positioning and if this is what's breaking your script then look into this.
Let's add the rest of the definitions
1 | local Sound = game.ReplicatedStorage:FindFirstChild( "Sound" ) |
2 | local Button = script.Parent |
3 | local Open = script.Parent.Parent.Parent:FindFirstChild( "Open" ) |
4 | local Frame = script.Parent.Parent |
Now that you have everything defined it's much more simpler.
1 | Button.MouseButton 1 Click:Connect( function () |
And if you put your definitions alongside it your final code will come out as.
01 | local Sound = game.ReplicatedStorage:FindFirstChild( "Sound" ) |
02 | local Button = script.Parent |
03 | local Open = script.Parent.Parent.Parent:FindFirstChild( "Open" ) |
04 | local Frame = script.Parent.Parent |
06 | Button.MouseButton 1 Click:Connect( function () |
Without the sound it will be.
1 | local Button = script.Parent |
2 | local Open = script.Parent.Parent.Parent:FindFirstChild( "Open" ) |
3 | local Frame = script.Parent.Parent |
5 | Button.MouseButton 1 Click:Connect( function () |
This is my first time doing an explanation like this tell me if you like it and if it's helpful please and thank you!