G’day. I created a script so that I can play background music in my game. Now I created a TextLabel that should display the Name of the Song that is currently playing. But I dont know how I should get the name of the song. Can someone help? Below is the script:
local SongsFolder = script['Songs']
local TextFrame = script.Parent.Parent:WaitForChild('ScreenGui'):WaitForChild('Frame'):WaitForChild('TextLabel')
while wait() do
for i,v in pairs(SongsFolder:GetChildren() ) do
v:Play()
v.Ended:Wait()
v.TimePosition = 0
end
end
TextFrame.TextLabel = "Now playing" --- Add the name of the song
wait(5)
TextFrame.TextLabel = ""
Simply store the sound instance in a local variable then show it’s name:
local SongsFolder = script['Songs']
local TextFrame = script.Parent.Parent:WaitForChild('ScreenGui'):WaitForChild('Frame'):WaitForChild('TextLabel')
local songPlaying -- instance of playing song
task.spawn(function() -- prevents infinite loop from yielding code
while wait() do
for i,v in pairs(SongsFolder:GetChildren() ) do
songPlaying = v -- sets songplaying to v
v:Play()
v.Ended:Wait()
v.TimePosition = 0
end
end
end)
TextFrame.TextLabel = "Now playing "..songPlaying.Name --- Add the name of the song
wait(5)
TextFrame.TextLabel = ""
Renaming all the sounds to the title of their soundId, and just using the .Name property of that Sound object.
Using MarketplaceService:GetProductInfo() to get the name automatically. This would look something like: (keep in mind SoundIds usually have “rbxassetid://” at the front, so you’d have to remove that and then use tonumber on the rest of the string to turn it into a number)
12:54:59.813 Infinite yield possible on 'Players.TtvRaucra:WaitForChild("ScreenGui")' - Studio
12:54:59.813 Stack Begin - Studio
12:54:59.813 Script 'Players.TtvRaucra.PlayerGui.BackgroundMusic', Line 2 - Studio - BackgroundMusic:2
12:54:59.813 Stack End - Studio
12:54:59.813 Infinite yield possible on 'Workspace.LightStorage:WaitForChild("EntranceZone")' - Studio
12:54:59.813 Stack Begin - Studio
12:54:59.813 Script 'Workspace.TtvRaucra.LightingOptimization', Line 36 - Studio - LightingOptimization:36
12:54:59.813 Stack End - Studio
12:55:00.677 :: Adonis :: Requiring Alerts Module by ID; Expand for module URL > ▶ {...} - Server
A small part of what is above it. All the Sound IDs that failed to load are not those who are in the Background Music Script by the way.
12:54:53.647 Stack Begin - Studio
12:54:53.647 Script 'Workspace.SCP.SCP-939.Animate', Line 14 - Studio - Animate:14
12:54:53.647 Stack End - Studio
12:54:53.647 Infinite yield possible on 'Workspace.shelter_blast:WaitForChild("DoorOpened")' - Studio
12:54:53.647 Stack Begin - Studio
12:54:53.647 Script 'Workspace.Doors.shelter_blast.DetectCut', Line 1 - Studio - DetectCut:1
12:54:53.647 Stack End - Studio
12:54:53.665 GroupID Morphs loaded. - Server - Attire handles:25
12:54:53.682 Failed to load sound rbxassetid://5475286926: Unable to download sound data - Studio
12:54:54.021 Animation Spoofer cannot run while game is running - Client
12:54:55.008 Failed to load sound rbxassetid://5475286926: Unable to download sound data - Studio
12:54:55.076 Requiring asset 6381249088.
Callstack:
cloud_6380577372.Tubemaker.Tubemaker, line 24
- Server
12:54:55.512 Failed to load sound rbxassetid://9174711793: Unable to download sound data - Studio
12:54:55.683 Failed to load animation - sanitized ID: rbxassetid://12933085934 - Studio
12:54:58.135 GroupID Morph System loaded. - Server
12:54:58.136 GroupID Morphs completed. - Server
12:54:58.209 require(assetId) cannot be called from a client. assetId = 6381249088 - Client
12:54:58.209 Stack Begin - Studio
12:54:58.209 Script 'cloud_6380577372.Tubemaker.Tubemaker', Line 24 - Studio
12:54:58.209 Stack End - Studio
12:54:58.277 TransitArms - Server - TransitSystem:96
12:54:58.281 TransitGate - Server - TransitSystem:97
12:54:58.308 TransitArms - Server - TransitSystem:96
12:54:58.309 TransitGate - Server - TransitSystem:97
12:54:58.386 ▶ [SlaveClock][GetTime] - Slave clock is not yet synced (x8) - Client - SyncedTime:86
12:54:58.452 Failed to load animation - sanitized ID: rbxassetid://11898686078 - Studio
12:54:58.553 PlayerLoader successful - Client - PlayerLoader:35
12:54:58.588 Section four complete - Client - Menu System:76
12:54:58.603 Failed to load animation - sanitized ID: rbxassetid://11898686078 - Studio
12:54:59.813 Infinite yield possible on 'Players.TtvRaucra:WaitForChild("ScreenGui")' - Studio