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

Claims my value isn't a table, how do I fix this?

Here is what I have

playing = false
local TableOfIDs = {"160594536","412765335","632668884","326087110","714630890"}
math.randomseed(tick())


while wait() do
if  playing == false then 
script.Music:Stop()
script.Music.SoundId = "http://www.roblox.com/Asset?ID="..(TableOfIDs{math.random(1,#TableOfIDs)})
script.Music:Play()
else
print (";D")
end
end

while wait() do
if script.Music.isPlaying == true then
playing = true
else
playing = false
end
end

And this is the error

Workspace.Script:9: attempt to call global 'TableOfIDs' (a table value)

I don't understand what is wrong...

1 comment

0

For your title, IT claims that it is a table value, because of the error.

1 answer

✓ Accepted answer

You're given this error because you tried using curly brackets, which are reserved for tables when you should have been using square brackets. You also tried to run two while statements without using a coroutine. Without wrapping the first while statement in a coroutine, your script will yield (wait) until that first while statement is broken out of to move on to the rest of the script. I changed that to work with the Ended event.

-- You don't need quotes on numbers
local TableOfIDs = {160594536,412765335,632668884,326087110,714630890}

-- Define variables for objects you will use later.
-- This prevents having to repeat yourself (DRY).
	-- and having errors when you don't utilize WaitForChild()

local Music = script:WaitForChild('Music')
local last_song
math.randomseed((tick() % 1) * 1e7)

local function play_newsong()
	print("new song")
	local new_song
	-- Don't want to repeat the last song!
	repeat 
		new_song = TableOfIDs[math.random(#TableOfIDs)]
	wait() 
	until new_song ~= last_song
	Music.SoundId = "http://www.roblox.com/Asset?ID="..( new_song )
	Music:Play()
	last_song = new_song
end

-- Use the Ended event instead and skip to the next song
	-- when the last song ended
Music.Ended:Connect(function()
	play_newsong()
end)

play_newsong()

4 comments

0

It appears to do nothing...

0

Where is the script located? Is it a normal script or local? What does the output say?.

0

It is a script not a local script and it was located in workspace and music was located inside it...

0

I looked into it, it was just glitching in studio idk why but it works thanks!

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