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

How do you add sounds when you get over a TextButton?

So i am not asking how to put a sound when u click a TextButton but like when the mouse is on it but didn't clicked.

1 answer

✓ Accepted answer

Well, you can use MouseEnter function provided by Roblox. It will detect whether the mouse has entered the TextButton. Also, you can use MouseLeave to detect if the mouse left the TextButton.

A sample code:

-- Local Script inside the TestButton

local TextButton = script.Parent

local function Enter() -- Creating a local function
	local sound = Instance.new("Sound") -- Creates a sound object
	sound.Parent = TextButton
	sound.Name = "TestSubject"
	sound.SoundId = "rbxassetid://12345678" -- An example

	sound:Play()
end

local function Leave()
	local Sound = TextButton:FindFirstChild("TestSubject")
	
	if Sound then -- If the Sound object is found
		Sound:Stop() -- Stops the sound
	end
end

TextButton.MouseEnter:Connect(Enter)
TextButton.MouseLeave:Connect(Leave)

Lemme know if it helps!

3 comments

0

It does work! Than you so much!!!

0

It will be helpful if you mark it as the answer

0

This happens often here, I'll accept it for you; you can use hyperlinks with the integrated StackEdit, it would be more educative to include documentation links to these RBXScriptSignals.

This discussion is preserved as it was. New answers, comments, and votes are closed.