Insert to playlist

I’m trying to make a tool that can insert into a radio playlist, so then whenever the next song proximity prompt is triggered, it plays the next song in the playlist

I have two scripts parented under the radio:

Insert:

script.Parent.Touched:Connect(function(op)
	if op.Name == "Handle" then
		if op.Parent.Name == "drop.mp3" then
			workspace.Songs.drop.Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "good days.mp3" then
			workspace.Songs["good days"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "happy.mp3" then
			workspace.Songs["happy"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "little loud ;).mp3" then
			workspace.Songs["little loud ;)"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "morning.mp3" then
			workspace.Songs["morning"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "video game.mp3" then
			workspace.Songs["video game"].Parent = workspace.Playlist
			op.Parent:Destroy()
		end
	end
end)

and the Play:

script.Parent.Touched:Connect(function(op)
	if op.Name == "Handle" then
		if op.Parent.Name == "drop.mp3" then
			workspace.Songs.drop.Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "good days.mp3" then
			workspace.Songs["good days"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "happy.mp3" then
			workspace.Songs["happy"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "little loud ;).mp3" then
			workspace.Songs["little loud ;)"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "morning.mp3" then
			workspace.Songs["morning"].Parent = workspace.Playlist
			op.Parent:Destroy()
		elseif op.Parent.Name == "video game.mp3" then
			workspace.Songs["video game"].Parent = workspace.Playlist
			op.Parent:Destroy()
		end
	end
end)

The play script is where I got an error ‘invalid argument #1 to pairs’. I’m not very experienced with for loops, so I don’t know what that means.

1 Like

What line does the error occurs at?

That is probably because you used a for loop with in pairs(), but the value that was put into pairs() is not a table. However, this is not related to the code you show us in your post. So try checking the line that at which the error is fired.

– Little tip
( value = to the value that is in your pairs() )
Make sure the value has :GetChildren() if you want the children
Make sure it’s a table. You can check this by doing print(value) to check if it’s, or not, a table.

sorry for the late response, line 5 in the play script

Cool and all but… What line in your code is that? Or is that your whole script? ← you dont have any pairs in that line
In any case, can you tell send me the whole error message? I want to confirm a little theory I have.

line 5 and down, sorry for the late response again.

It’s alright, but more importantly, there’s not pairs() in that line. Are you sure that’s the error? can you send me the whole error? Secondly, please send the exact line that is (check by clicking on the error. to make sure it redirects to the exact line)

EDIT: I think there’s a big misunderstanding here. The first code is the same as the second one. Maybe you got confused because of that.

Oh! I didn’t notice,

local Sound = script.Parent.Sound
local Template = 'http://www.roblox.com/asset/?id='

script.Parent.Prompt.Triggered:Connect(function()
	for i, v in pairs(workspace.Playlist) do
		Sound.SoundId = Template..''..v
		Sound:Play()
	end
end)
1 Like

workspace.Playlist:GetChildren()
this took 17 days lol