✓ Accepted answer
Using UserInputService's events here would be completely unnecessary. The InputBegan and InputEnded events of GUIButtons should be all you need. For only mouse input, you could as well just use the MouseButton1Down and MouseButton1Up events (Roblox might fire these mouse events even for touch input but they really shouldn't be used for such).
local function isValidInput(inputObject)
return inputObject.UserInputType == Enum.UserInputType.MouseButton1
or inputObject.UserInputType == Enum.UserInputType.Touch
end
button.InputBegan:Connect(function(inputObject)
if isValidInput(inputObject) then
sound:Play()
button.InputEnded:Wait()
sound:Stop()
end
end)
1 comment
https://wiki.roblox.com/index.php?title=API:Class/GuiButton - Look at the events part