The currentTrack.Value isn’t changing to that songs name that is playing, and here’s the code on what I want it
Music.Name = "ServerMusic"
Music.Parent = workspace
local currentTrack = workspace.Songs.CurrentTrack
--[[
Set the track's wait time to nil if you want the full track to play
]]
-- // [Index] not required due ot lua doing it automatically
local MusicTracks = {
{
Name = "Sub Zero";
Id = "1576032985";
currentTrack.Value = MusicTracks.Name
WaitTime = 117.472 * 2;
};
{ Name = "Jocelyn Flores";
Id = "426082642";
currentTrack.Value = MusicTracks.Name
WaitTime = 120.084 * 2;
};
}
coroutine.wrap(function()
local LastIndex = 0
while true do
if LastIndex == #MusicTracks then
LastIndex = 0
end
LastIndex += 1
local MusicTrackData = MusicTracks[LastIndex]
Music.TimePosition = 0
Music.SoundId = "rbxassetid://" .. MusicTrackData.Id
Music:Play()
if MusicTrackData.WaitTime then
task.wait(MusicTrackData.WaitTime)
else
Music.Ended:Wait()
end
end
end)()
The first reason why it is not randomized is because you are using the second method which play music in from a predefined list.
the second reason the track name isn’t being changed is because tables can only store information
try this instead
local Music = Instance.new("Sound")
Music.Name = "ServerMusic"
Music.Parent = workspace
local currentTrack = workspace.Songs.CurrentTrack
--[[
Set the track's wait time to nil if you want the full track to play
]]
-- // [Index] not required due ot lua doing it automatically
local MusicTracks = {
{
Name = "Sub Zero";
Id = "1576032985";
WaitTime = 117.472 * 2;
};
{
Name = "Jocelyn Flores";
Id = "426082642";
WaitTime = 120.084 * 2;
};
}
--[[
{
Name = "Sub Zero";
Id = "1576032985";
currentTrack.Value = MusicTracks.Name
WaitTime = 117.472 * 2;
};
This piece of code will not work, it will error because you are trying to run raw code inside of a table.
tables can only store data
use this instead, the song looper will automatically grab the name data from the table and change the value from there.
{
Name = "Sub Zero";
Id = "1576032985";
WaitTime = 117.472 * 2;
};
--]]
coroutine.wrap(function()
local LastIndex = 0
while true do
local RandomTrackIndex = math.random(1, #MusicTracks)
local MusicTrackData = MusicTracks[RandomTrackIndex]
Music.TimePosition = 0
Music.SoundId = "rbxassetid://" .. MusicTrackData.Id
Music:Play()
if currentTrack then
currentTrack.Value = MusicTrackData.Name
end
if MusicTrackData.WaitTime then
task.wait(MusicTrackData.WaitTime)
else
Music.Ended:Wait()
end
end
end)()
sorry for bugging you so much I’m just trynna get this working I appreciate the help though truely… So, the values work - but… It’s showing the wrong song like if Jocelyn Flores plays, It shows Sub Zero is playing, and if Sub Zero is playing it shows Jocelyn Flores is playing.
last time before I close this all I need to know is how you add more songs to the list here’s what I’ve tried doing
Music.Name = "ServerMusic"
Music.Parent = workspace
local currentTrack = workspace.Songs.CurrentTrack
--[[
Set the track's wait time to nil if you want the full track to play
]]
-- // [Index] not required due ot lua doing it automatically
local MusicTracks = {
{
Name = "Sub Zero";
Id = "426082642";
WaitTime = 120.084 * 2;
};
{
Name = "Slow Motion";
Id = "314023820";
WaitTime = 120.216 * 2;
};
}
{
Name = "Just For The Night";
Id = "281057206";
WaitTime = 80.169 * 2;
};
}
coroutine.wrap(function()
local LastIndex = 0
while true do
local RandomTrackIndex = math.random(1, #MusicTracks)
local MusicTrackData = MusicTracks[RandomTrackIndex]
Music.TimePosition = 0
Music.SoundId = "rbxassetid://" .. MusicTrackData.Id
Music:Play()
if currentTrack then
currentTrack.Value = MusicTrackData.Name
end
if MusicTrackData.WaitTime then
task.wait(MusicTrackData.WaitTime)
else
Music.Ended:Wait()
end
end
end)()
I'm getting an error, and idk how to add more songs, or what to do on the last song when it loops to the top once again and so on.
this will not work as for you tried adding another table end (as seen at the last line in the quote)
to add another track you need to put another table inside of music tracks.
local MusicTracks = {
{
Name = "Sub Zero";
Id = "426082642";
WaitTime = 120.084 * 2;
};
{
Name = "Slow Motion";
Id = "314023820";
WaitTime = 120.216 * 2;
};
{
Name = "Just For The Night";
Id = "281057206";
WaitTime = 80.169 * 2;
};
} -- // This is the end, do not try and add tracks past this point
Music.Name = "ServerMusic"
Music.Parent = workspace
local currentTrack = workspace.Songs.CurrentTrack
--[[
Set the track's wait time to nil if you want the full track to play
]]
-- // [Index] not required due ot lua doing it automatically
local MusicTracks = {
{
Name = "Sub Zero";
Id = "426082642";
WaitTime = 120.084 * 2;
};
{
Name = "Slow Motion";
Id = "314023820";
WaitTime = 120.216 * 2;
};
{
Name = "Just For The Night";
Id = "281057206";
WaitTime = 80.169 * 2;
};
{
Name = "Jocelyn Flores";
Id = "1576032985";
WaitTime = 117.472 * 2;
};
{
Name = "Hotel";
Id = "3102955100";
WaitTime = 327.523 * 2;
};
} -- // This is the end, do not try and add tracks past this point
coroutine.wrap(function()
local LastIndex = 0
while true do
local RandomTrackIndex = math.random(1, #MusicTracks)
local MusicTrackData = MusicTracks[RandomTrackIndex]
Music.TimePosition = 0
Music.SoundId = "rbxassetid://" .. MusicTrackData.Id
Music:Play()
if currentTrack then
currentTrack.Value = MusicTrackData.Name
end
if MusicTrackData.WaitTime then
task.wait(MusicTrackData.WaitTime)
else
Music.Ended:Wait()
end
end
end)()
Also… It’s not playing anymore songs after 1 plays, it just breaks but no errors show?
Music.Name = "ServerMusic"
Music.Parent = workspace
local currentTrack = workspace.Songs.CurrentTrack
--[[
Set the track's wait time to nil if you want the full track to play
]]
-- // [Index] not required due ot lua doing it automatically
local MusicTracks = {
{
Name = "Sub Zero";
Id = "426082642";
WaitTime = 120.084 * 2;
};
{
Name = "Slow Motion";
Id = "314023820";
WaitTime = 120.216 * 2;
};
{
Name = "Just For The Night";
Id = "281057206";
WaitTime = 80.169 * 2;
};
{
Name = "Jocelyn Flores";
Id = "1576032985";
WaitTime = 117.472 * 2;
};
{
Name = "Hotel";
Id = "3102955100";
WaitTime = 327.510 * 2;
};
{
Name = "Homies";
Id = "1209456869";
WaitTime = 220.368 * 2;
};
} -- // This is the end, do not try and add tracks past this point
coroutine.wrap(function()
local LastIndex = 0
while true do
local RandomTrackIndex = math.random(1, #MusicTracks)
local MusicTrackData = MusicTracks[RandomTrackIndex]
Music.TimePosition = 0
Music.SoundId = "rbxassetid://" .. MusicTrackData.Id
Music:Play()
if currentTrack then
currentTrack.Value = MusicTrackData.Name
end
if MusicTrackData.WaitTime then
task.wait(MusicTrackData.WaitTime)
else
Music.Ended:Wait()
end
end
end)()
Yes, that is how you add more tracks.
But the music stopping after the first track, that is a little confusing as for when I tested, it worked perfectly. Not sure what happened on your end
He wants to have custom wait times for some songs because some songs have extra goodies at the end.
So in short, he would like to prematurely end the song.