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

I need help with this Music Gui?

Asked by
CHATED 10
10 years ago

I'm trying to make it when you click the TextButton the text changes from "Play" to "Stop" then you can click it when it says "Stop" and it will stop the sound. Here's the current script.

local ContentProvider = game:GetService("ContentProvider")

local totalWait = 20

local queueSize = ContentProvider.RequestQueueSize

function UpdateQueueSize()
    queueSize = ContentProvider.RequestQueueSize
end


function WaitForSoundToLoad()
    local start = tick()
    while (ContentProvider.RequestQueueSize > queueSize) and ((tick() - start) < totalWait ) do
        wait(0.1)
    end
    if (start - tick() > 1) then print("Took " .. tostring(start - tick()) " seconds to load") end
end

function PlaySound(id)
    local sound = Instance.new("Sound")
    sound.SoundId = "http://www.roblox.com/asset?id=" .. tostring(id)
    UpdateQueueSize()
    if game.Players.LocalPlayer.PlayerGui:FindFirstChild("Sound") then
        else
    sound.Parent = game.Players.LocalPlayer.PlayerGui
    WaitForSoundToLoad()
    sound:Play()
    end
    end

local TextBox = script.Parent
local TextButton = script.Parent.Parent.PlaySong.Toggle

TextBox.FocusLost:connect(function(enterPressed)
    Game:GetService("ContentProvider"):Preload(TextBox.Text)
end)

TextButton.MouseButton1Click:connect(function()
    PlaySound(tonumber(TextBox.Text))
end)

1 answer

Log in to vote
0
Answered by 10 years ago

I don't usually give the immediate solution, but here it is anyway: Just edit line 2

Button = script.Parent --This means you put this script in that button.
Sound = --Put the path to the sound HERE
debounce = false --To prevent infinite clicks. DO NOT CHANGE
script.Parent.MouseButton1Clicked:connect(function()
    if debounce == false then
        debounce = true
        if script.Parent.Text == "Play" then --Text is Play
            script.Parent.Text = "Stop"
            Sound:Play()
        else --Text is Stop
            Sound:Stop()
            script.Parent.Text = "Play"
        end
    end
    wait(1)
    debounce = false
end)

What this does, is when the button is clicked, it checks if the text is equal to"Stop", the Music stops and the other way round.

Ad

Answer this question