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)
