I want to make an IMAGE BUTTON play a sound on click, and make it clickable by using a key. Any help?
COMMUNITY QUESTION
How can I make a image button play a sound when I click it?
1 answer
Whenever you want to detect if a player clicked a button, you would use MouseButton1Click. Whenever you want to detect if a player inputted a key, you would use UserInputService.InputBegan.
local button = script.parent
local UIS = game:GetService("UserInputService")
local sound = --Wherever the sound is
button.MouseButton1Click:Connect(function()
sound:Play()
end)
UIS.InputBegan:Connect(function(input, gameProcessedEvent)
if input.KeyCode == Enum.KeyCode.KEYHERE then
sound:Play()
end
end)
2 comments
0
This question sounds dumb lol, but where would i put it?
0
You put the script in the button
This discussion is preserved as it was. New answers, comments, and votes are closed.

2 comments
sound:Play()
script.Parent.MouseButton1Down:Connect(function()