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

I need help with this Music Gui?

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

✓ Accepted answer

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.

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