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

MP3 Player Script Not Working As Far As I Got, Any Help?

So, I'm making a MP3 player and when I test it it prints out an error.

Error: 22:39:04.346 - Players.FuriaI.PlayerGui.mp3player.BackGround.Main:38: attempt to get length of local 'v' (a number value) 22:39:04.346 - Stack Begin 22:39:04.347 - Script 'Players.FuriaI.PlayerGui.mp3player.BackGround.Main', Line 38 - global ChangeSong 22:39:04.347 - Script 'Players.FuriaI.PlayerGui.mp3player.BackGround.Main', Line 47

Script:

local Player = game.Players.LocalPlayer
repeat wait() until Player.Character
local Character = Player.Character
local Bg = script.Parent
local Bar = Bg.Bar
local PlayPause = Bg.PlayPause
local Prev = Bg.Prev
local Next = Bg.Next
local SongImg = Bg.ImageLabel
local Song = Bg.Song
local Time = Bg.Time
local SongIsPlaying = false

local SoundIds = {
	897623161,844906598,
}

local ChosenSong = {}

table.sort(SoundIds)

function GetIndex(tabl)
	for i,v in pairs(tabl) do
		return v
	end
end

function CheckIfPlaying()
	if SongIsPlaying == true then
		return true
	elseif SongIsPlaying == false then
		return false
	end
end

function ChangeSong()
	for i,v in pairs(SoundIds) do
		table.insert(ChosenSong,math.random(1,#v))
		table.remove(SoundIds,GetIndex(ChosenSong))
	end
end

function PlaySong()
	
end

ChangeSong()

The Error Is When It Does table.insert And table.remove

1 answer

✓ Accepted answer

#v is shorthand for the number of entries in the array v, and considering that v is a value in the array SoundIds (and not an array itself), it is erroring.

Try something like this:

function changesong()
	local index = math.random(1, #SoundIds);
	table.insert(ChosenSong, SoundIds[index]);
	table.remove(SoundIds, index);
end

1 comment

0

Thank you, It gave me no errors and works perfectly so far!

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