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.
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.
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
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
local Sound = game.ReplicatedStorage:FindFirstChild("Sound")
local Button = script.Parent
local Open = script.Parent.Parent.Parent:FindFirstChild("Open")
local Frame = script.Parent.Parent
Now that you have everything defined it's much more simpler.
Button.MouseButton1Click:Connect(function()
Sound:Play()
Open.Visible = true
Frame.Visible = false
end)
And if you put your definitions alongside it your final code will come out as.
local Sound = game.ReplicatedStorage:FindFirstChild("Sound")
local Button = script.Parent
local Open = script.Parent.Parent.Parent:FindFirstChild("Open")
local Frame = script.Parent.Parent
Button.MouseButton1Click:Connect(function()
Sound:Play()
Open.Visible = true
Frame.Visible = false
end)
Without the sound it will be.
local Button = script.Parent
local Open = script.Parent.Parent.Parent:FindFirstChild("Open")
local Frame = script.Parent.Parent
Button.MouseButton1Click:Connect(function()
Open.Visible = true
Frame.Visible = false
end)
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!
6 comments
Are you looking for it to make a noise when you close it, or just want it to close?
If you are using the visible property, please make sure that "open" and "script.Parent.Parent" are both NOT screenguis
@BryanFehr (im not sure if thats how you reply) yes i want it to only close
Use Debounce.
how?
how?