Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I make a image button play a sound when I click it?

I want to make an IMAGE BUTTON play a sound on click, and make it clickable by using a key. Any help?

2 comments

0

sound:Play()

0

script.Parent.MouseButton1Down:Connect(function()

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.