Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

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

Asked by 6 years ago

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...

0
For your title, IT claims that it is a table value, because of the error. hiimgoodpack 2009 — 6y

1 answer

Log in to vote
0
Answered by
Azarth 3141 Moderation Voter Community Moderator
6 years ago
Edited 6 years ago

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()
0
It appears to do nothing... Yodaisme 2 — 6y
0
Where is the script located? Is it a normal script or local? What does the output say?. Azarth 3141 — 6y
0
It is a script not a local script and it was located in workspace and music was located inside it... Yodaisme 2 — 6y
0
I looked into it, it was just glitching in studio idk why but it works thanks! Yodaisme 2 — 6y
Ad

Answer this question