Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
1

I made a script and tested it, and it didn't work, what did I do wrong?

Asked by 8 years ago

I was making a script with a SurfaceGUI button that would play/stop music if it was clicked on. It tried the below script but it didn't work.

local button = script.Parent
local sound = button:WaitForChild('Sound')

local function onButtonClick()
    if sound.IsPlaying then
        sound:Stop()
        else sound:Play()
    end
end

button.MouseButton1Click:connect(onButtonClick)

What did I do wrong?

0
First off, are you using a local script? Conmmander 479 — 8y
0
Yes, I am using a local script, but the button is visible to the entire server (it's on a brick). SPBOnion 30 — 8y

1 answer

Log in to vote
0
Answered by 8 years ago

So you were accessing the button not the sound when you did your sound variable.

--Make sure the sound is inside the frame.
local button = script.Parent
local sound = script.Parent.Parent.Sound --Put the name of the sound object here

local function onButtonClick()
    if sound.IsPlaying then
        sound:Stop()
    else 
        sound:Play()
    end
end

button.MouseButton1Click:connect(onButtonClick)
0
I copy/pasted the script above and the sound didn't play when I clicked the button. SPBOnion 30 — 8y
0
A regular script works just not a LocalScript. BennyBoiOriginal 293 — 8y
0
it still isn't working SPBOnion 30 — 8y
0
Where is your sound? Also, open your output to check for errors and are you using a normal script? BennyBoiOriginal 293 — 8y
View all comments (6 more)
0
1. My sound is located in the item "SurfaceGUI" 2. I'm using a normal script 3. Output is blank. I click on the button and nothing happens, but no error. SPBOnion 30 — 8y
0
Make the Sound in the same frame as the Button. BennyBoiOriginal 293 — 8y
0
Alright, my script is NOT local, and the sound is located in the same object as the button. Yet, nothing is happening. Do you think it could be an error with the sound itself, or with the GUI? I've tried everything and no music is playing at all. SPBOnion 30 — 8y
0
Do you have an ID in the sound? BennyBoiOriginal 293 — 8y
0
yes SPBOnion 30 — 8y
0
Okay so the button is in the same frame as the sound right? If it isnt then it would need to be. And is the sound named sound? BennyBoiOriginal 293 — 8y
Ad

Answer this question