-- Variables
local main = script.Parent:WaitForChild("Main")
local sound = script.Parent:WaitForChild("Sound")
local songs = {5034180086,1112199032,4513732143,4606400466,621227155} -- Songs go in here (ID ONLY)
local progress = main:FindFirstChild("ProgressBar").Progress
local songName = main:FindFirstChild("SongName")
-- Main Script
while wait() do -- Repeats itself continuously
sound:Stop() -- Stops the music
progress.Size = UDim2.new(0,0,1,0) -- Resets the song's progressbar
if not sound.IsPlaying then -- If the song has stopped
local songChosen = songs[math.random(1,#songs)] -- Chooses a random sound
local asset = game.MarketplaceService:GetProductInfo(songChosen) -- Gets the sound's info
sound.SoundId = "rbxassetid://".. songChosen
sound:Play()
songName.Text = asset.Name -- Changes to text to the sound's name
wait(1) -- Prevents errors
progress:TweenSize(UDim2.new(1,0,1,0),'Out','Linear',(sound.TimeLength)-1) -- Moves progress bar
wait((sound.TimeLength)-1) -- Waits sound's time -1
end
end
COMMUNITY QUESTION
Music restarting everytime the player dies, how to fix it?
1 answer
Try This: if doesn't work put in sever script service, I think the reason is you didn't put the player added function.
game.Players.PlayerAdded:Connect(function(plr)
-- Variables
local main = script.Parent:WaitForChild("Main")
local sound = script.Parent:WaitForChild("Sound")
local songs = {5034180086,1112199032,4513732143,4606400466,621227155} -- Songs go in here (ID ONLY)
local progress = main:FindFirstChild("ProgressBar").Progress
local songName = main:FindFirstChild("SongName")
-- Main Script
while wait() do -- Repeats itself continuously
sound:Stop() -- Stops the music
progress.Size = UDim2.new(0,0,1,0) -- Resets the song's progressbar
if not sound.IsPlaying then -- If the song has stopped
local songChosen = songs[math.random(1,#songs)] -- Chooses a random sound
local asset = game.MarketplaceService:GetProductInfo(songChosen) -- Gets the sound's info
sound.SoundId = "rbxassetid://".. songChosen
sound:Play()
songName.Text = asset.Name -- Changes to text to the sound's name
wait(1) -- Prevents errors
progress:TweenSize(UDim2.new(1,0,1,0),'Out','Linear',(sound.TimeLength)-1) -- Moves progress bar
wait((sound.TimeLength)-1) -- Waits sound's time -1
end
end
end)
2 comments
0
I put this script in this properties it's work [Starter Gui > MusicGui (ScreenGui) > MasterScript (LocalScript)]
0
it's not working
This discussion is preserved as it was. New answers, comments, and votes are closed.

5 comments
Can anyone edit my script ?
Where is your music parented to?
Starter Gui > MusicGui (ScreenGui) > MasterScript (LocalScript)
Put it in StarterCharacter
it's not working