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

What am i doing wrong here?

I am not very experienced with i,v pairs but i want to be able to start using them. It makes scripting easier and more organized. This is what i tried and it doesn't work, can someone tell me exactly what I'm doing wrong

songs = {"rbxassetid://236764932","rbxassetid://145154345","rbxassetid://202376551"}

local folder = Instance.new("Folder",player.PlayerGui)

for i,v in pairs(songs)do
	print(v)
	song = Instance.new("Sound")
	song.Parent = folder
	song.Volume = 1
	song.SoundId = v
	song:Play()
	wait(song.TimeLength)
	song:Destroy()
	wait()
end


plz help me................................

2 comments

0

You have to give us the output for us to help.

0

player isn't defined

1 answer

✓ Accepted answer

There are two issues with your script. The first is you never defined what/who player was. Secondly, you can not call on song.TimeLength. as it returns 0. To test this, just do wait(song.TimeLegth), it returns as 0. Here is the fixed script that plays the music in the folder.

game.Players.PlayerAdded:connect(function(player)
	local songs = {"rbxassetid://236764932","rbxassetid://145154345","rbxassetid://202376551"}
	local folder = Instance.new("Folder", player.PlayerGui)

for i,v in pairs(songs)do
	wait()
    print(v)
    local song = Instance.new("Sound", folder)
    song.SoundId = v
    song.Volume = 1
    song:Play()
    wait(90) --Because you can't wait the TimeLength, you just have to wait 90 seconds (the Length of the first song played)
    song:Destroy()
    wait()
end
end)

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