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

This was scripted a while ago. Why doesn't this music script work?

Asked by 6 years ago

So, this script was scripted a while ago and I can't seem to figure out why it doesn't work.

brick=script.Parent
other=brick.Parent.stop
music=brick.Parent.music3

script.Parent.ClickDetector.MouseClick:connect(function(player)
        music:Play()
    end
1
You are missing a closing parentheses on your last end. Should be end). amanda 1059 — 6y

2 answers

Log in to vote
0
Answered by 6 years ago

Alright so the problem here is that you're missing a ")", to fix this, put a ")" in the 7th line, the code should look like this:

local brick=script.Parent
local other=brick.Parent.stop
local music=brick.Parent.music3

brick.ClickDetector.MouseClick:connect(function(player)
        music:Play()
end)
Ad
Log in to vote
0
Answered by 6 years ago

We have a few main things you want to check.

1st, this is the reason the script isn't working. At line 7 you are missing a ) we need this ) there because it is closing a function. If we were making a loop or if statement we do not need this because you can just drop it anywhere in the code. A function is different however and I'll show why below.

blah blah blah (<<< function(player)
    code
    code
    code
end <<<

Look at the bracket surrounding the initial function part and look at the rest of the function. This bracket has gone unanswered which makes the function think that all the rest of the code beneath it is part of it. That is why we need the bracket there.

The correct code looks like this:

script.Parent.ClickDetector.MouseClick:connect(function(player)
        music:Play()
end)

But we still have a couple other things to check.

I'm not sure what "other=brick.Parent.stop" is doing. Is there somewhere else in the script that needs that? Or else we can just remove it. For the purpose of the final script I'm going to leave that in.

Next is this part: "script.Parent.ClickDetector.MouseClick:connect." We can swap out script.Parent for brick. We don't shorten directories for nothing!

So here is our final code. I'm going to clean it up a bit, and leave in other=brick.Parent.stop for the sake of assuming it has some other importance.

local brick=script.Parent
local other=brick.Parent.stop
local music=brick.Parent.music3

brick.ClickDetector.MouseClick:connect(function(player)
        music:Play()
end)

Hope this helps :)

Answer this question