On line 2 you're calling the Play method of BGMusic1. This doesn't return anything, so the second line never runs.
Sounds have a property called IsPlaying, so your code would work like so:
function onTouched(hit)
if game.Workspace.BackgroundMusic1.IsPlaying then
game.Workspace.BackgroundMusic1:Pause()
end
end
script.Parent.Touched:connect(onTouched)
However, it's not necessary to even make that check. Pausing a paused Sound does nothing at all.
There is a different check that must be made, though, to see if the Part that hit this brick belongs to a Player and isn't some debris from the workspace:
function onTouched(hit)
if game.Players:GetPlayerFromCharacter(hit.Parent) then
game.Workspace.BackgroundMusic1:Pause()
end
end
script.Parent.Touched:connect(onTouched)
2 comments
Hope you can be able to read the script :/
In the future, you can select the code and click the Lua symbol above the text box to apply the code formatting yourself.