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

How to play sound when button clicked?

Asked by 4 years ago
Edited 4 years ago

So im making a gui and i want the buttons to play a sound when somebody click on it i tried doing

Helpbutton.MouseButton1Click:Connect(function()
    Help.Sound:Play
    wait(.1)
    Help.Sound:Stop
end)

but then this error comes

Players.Noman538.PlayerGui.Help.LocalScript:3: Expected '(', '{' or <string>, got 'wait'

2 answers

Log in to vote
0
Answered by
Ziffixture 6913 Moderation Voter Community Moderator
4 years ago

Play and Stop are both methods of Sound. In other words, they're functions. Basic syntax requires parentheses to wrap the function call as a form of providing arguments to the given parameters. Even without parameters that are built into functions, this practice is still mandatory across all languages. To fix this issue, place a pair of parentheses at the respective places.

Sound:Play()
Sound:Stop()
Ad
Log in to vote
0
Answered by
waifuSZN 123
4 years ago

The correct notation is :Play() and :Stop()

Answer this question