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

How do you add sounds when you get over a TextButton? [closed]

Asked by
DashDQ 17
3 years ago

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.

Closed as Not Constructive by Ziffixture

This question has been closed because it is not constructive to others or the asker. Most commonly, questions that are requests with no attempt from the asker to solve their problem will fall into this category.

Why was this question closed?

1 answer

Log in to vote
3
Answered by 3 years ago
Edited 3 years ago

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!

0
It does work! Than you so much!!! DashDQ 17 — 3y
0
It will be helpful if you mark it as the answer BestCreativeBoy 1395 — 3y
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. Ziffixture 6913 — 3y
Ad