Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Random Music Player MAKING ME SUPER MAD! Not working??????????????

Hello, I am trying to make a music player and it is making me furious. It is about the TimeLength. When I set it to the TimeLength it just cycles through a whole bunch of songs and it doesnt work.

--[[

-- Just create a model in Lighting named "Music", Insert music objects, and go!

make each music a different name.





]]
local player = game.Players.LocalPlayer
local musicplayer = "RandomMusicPlayer"
script.Name = "squidiskool's "..musicplayer
local stuff = game.Lighting:findFirstChild("Music") -- The name of the model where the music is. The model must be in Lighting!											
if stuff ~= nil then
music = stuff:GetChildren()



print(""..musicplayer..": <Loaded!>")
wait(10)
print(""..musicplayer..": <Enabled!>")
if #music <= 0 then 
print("[ERROR]"..musicplayer..": no music found in the music model")
else
	while true do
	local num = math.random(1,#music)
	local currentmusic = music[num]:Clone()
	wait(0.1)
		print("New music: "..currentmusic.Name)
	currentmusic.Parent = workspace	
	currentmusic:play()
	wait(currentmusic.TimeLength)
	currentmusic:pause()
	currentmusic.Parent = game.Lighting
	end
end																																			
else 
print("[ERROR]"..musicplayer..": Couldn't find the music model, make sure the model name is spelled correctly (caps sensitive)")
end





2 comments

0

just delete prints

0

No No No! It doesn't play the SONG at ALL! Prints need me to understand what this script it doing. IT IS JUST CYCLING THROUGH THE SONGS!

1 answer

✓ Accepted answer

Alright. So, the music length isn't a good way to do the wait function. Instead, use the Ended event. Here is the code:

--[[

-- Just create a model in Lighting named "Music", Insert music objects, and go!

make each music a different name.





]]
local player = game.Players.LocalPlayer
local musicplayer = "RandomMusicPlayer"
script.Name = "squidiskool's "..musicplayer
local stuff = game.Lighting:findFirstChild("Music") -- The name of the model where the music is. The model must be in Lighting!                                         
if stuff ~= nil then
music = stuff:GetChildren()



print(""..musicplayer..": <Loaded!>")
wait(10)
print(""..musicplayer..": <Enabled!>")
if #music <= 0 then 
print("[ERROR]"..musicplayer..": no music found in the music model")
else
    while true do
    local num = math.random(1,#music)
    local currentmusic = music[num]:Clone()
    wait(0.1)
        print("New music: "..currentmusic.Name)
    currentmusic.Parent = workspace 
    currentmusic:play()
    currentmusic.Ended:Wait() -- Instead of wait(currentmusic.TimeLength)
    currentmusic:pause()
    currentmusic.Parent = game.Lighting
    end
end                                                                                                                                         
else 
print("[ERROR]"..musicplayer..": Couldn't find the music model, make sure the model name is spelled correctly (caps sensitive)")
end

Contact me if you have any questions. Don't forget to upvote and accept if it helped.

1 comment

1

Now it's working!

This discussion is preserved as it was. New answers, comments, and votes are closed.