Music gui script

Alr guys am trying to make this gui in which it shows the name of the song and a progress bar but i want to put the sound in workspace but the script only runs when its in surfacegui with the gui obviously so i wanted to know how can i make the script know where is the sound located currently its says it is on script.parent so what i want is to make it know that the sound is in workspace

local main = script.Parent:WaitForChild(“Main”)
local sound = script.Parent:WaitForChild(“Sound”)
local songs = {725061858,569556642,327081386,669936570,970219205} – Songs go in here (ID ONLY)
local progress = main:FindFirstChild(“ProgressBar”).Progress
local songName = main:FindFirstChild(“SongName”)

– Main Script

while wait() do
sound:Stop()
progress.Size = UDim2.new(0,0,1,0)
if not sound.IsPlaying then
local songChosen = songs[math.random(1,#songs)]
local asset = game.MarketplaceService:GetProductInfo(songChosen)
sound.SoundId = “rbxassetid://”… songChosen
sound:Play()
songName.Text = asset.Name
wait(1) – Prevents errors
progress:TweenSize(UDim2.new(1,0,1,0),‘Out’,‘Linear’,(sound.TimeLength)-1)
wait((sound.TimeLength)-1) – Waits sound’s time -1
end
end

You’d just change it to workspace.Sound (workspace is a global variable which acts like a shortcut for game.Workspace).

For example:

local sound = workspace.Sound

FYI: Please make sure to format your code when posting it on the devforums:
```
Code here
```

1 Like

Thank you very much, Sure ill make that am new in the dev forums.

1 Like