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

Im Making A Music Gui But Dont Know How To Make The Music Play When You Put In a Music ID?

i have a gui that if you put in the music id In a Textbox then press play it inserts a sound and put's in the music id in the sound object but i dont know how to do that, can you help?

1 answer

✓ Accepted answer

Change the gui or the textbox and playbutton directory to what you have or just use the script as a guide. Lines 5,8,9 and 10 aren't necessary, but it gives a nice fade effect when stopping a previous sound.

local gui = script.Parent
local textbox = gui.TextBox
local playbutton = gui.TextButton
local currentmusic = nil
local tweenService = game:GetService("TweenService")--Tween just for fancy effect
function playMusic()
	if currentmusic ~= nil and typeof(currentmusic) == "Instance" and currentmusic:IsA("Sound") then
		local tween = tweenService:Create(currentmusic,TweenInfo.new(1,Enum.EasingStyle.Linear),{Volume = 0})
		tween:Play()
		tween.Completed:Wait()
		currentmusic:Destroy()
	end
	currentmusic = Instance.new("Sound")
	currentmusic.SoundId = "rbxassetid://" ..textbox.Text --Id from textbox
	currentmusic.Looped = true
	currentmusic.Volume = 1
	currentmusic.Parent = gui
	currentmusic:Play()
end
playbutton.MouseButton1Click:Connect(playMusic)

1 comment

0

thanks it works great!

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