Okay, Im making a music player. The problem is its just not playing. Sometimes it does and sometimes it doesn’t. Im not sure what is the problem but I have a hunch its the Sound.Ended however im not to sure please help me check my code if anything is wrong Im extremely confused.
local MarketPlaceService = game:GetService("MarketplaceService")
local currentSound = game.ReplicatedStorage:FindFirstChild("CurrentMusic")
local songs = script:GetChildren()
local TVs = game.Workspace.TVScreens:GetChildren()
local checkfirstid = 0
local checksecondid = 0
local checkthirdid = 0
while true do
checkthirdid = checksecondid
checksecondid = checkfirstid
local que = math.random(1,#songs)
local id = songs[que].Value
print("Song: "..id)
currentSound.SoundId = "rbxassetid://" ..id
if id == checkfirstid or id == checksecondid or id == checkthirdid then
currentSound.TimePosition = currentSound.TimeLength
print("Detected Reused Song")
end
currentSound:Play()
print("PlayingSong")
currentSound.Loaded:Wait()
local timelength = currentSound.TimeLength
for i, model in pairs(TVs) do
local songInfo = MarketPlaceService:GetProductInfo(id)
model.Screen.SurfaceGui.Frame.MusicName.Text = songInfo.Name.." - "..id
end
currentSound.Ended:Wait()
print("Song Ended")
checkfirstid = id
end
Yes, the song is already playing which is why you don’t need to wait for the song to load anymore. Although if you would like to wait for it to load, you should put the currentSound.Loaded:Wait() before the line where you played the sound.