Still have questions? Join our Discord server and get real time help.
Log in to vote

What is wrong with this script?

Asked by 5 years ago

Please make your question title relevant to your question content. It should be a one-sentence summary in question form.

I got my answer from putting music in each decal slides or the ones that needs it. But the one problem is that it has an error to the script. This is the script and error:

local bin = script.Parent
local decal = bin.Decal
local sound ="Sound", bin) -- Creates a sound object to play assets

local MainSlides = {
    {'', 189421358, 15},
    {'', nil, 3},
    {'', nil, 3},
    {'', nil, 3},
    {'', 160442087, 3},
    {'', nil, 3}
    -- You can add sounds where you want, just make sure they are in the correct index of the table.
    -- If you do not want a sound on the slide, put nil where the asset ID would go.

function getNumTabs(tab)
    local num = 0
    for i,v in pairs(tab) do num = num + 1 end
    return num

function runTable(tab)
    for i = 1,getNumTabs(tab) do
        local currentTab = tab[tostring(i)]

        if currentTab[2] ~= nil then  -- If there is an asset ID given then
            sound.SoundId = currentTab[2] -- Load asset ID into sound
            sound:Play() -- Play the sound

        decal.Texture = currentTab[1]
        sound:Pause() -- Pauses the sound

local c = game.Workspace.Countdown.SurfaceGui.TextLabel

function countDown()
    for timeLeft = 20, 0, -1 do
        c.Text = timeLeft
    c.Text = "Movie has started!"

while true do


00:09:23.912 - Workspace.Part.SlideScript:358: attempt to index local 'currentTab' (a nil value)

Thank you!

1 answer

Log in to vote
Answered by
BlueTaslem 17922 Moderation Voter Administrator Community Moderator Super Administrator
5 years ago

MainSlides is a list. That means the indices are 1, 2, 3, ....

The indices are not the text "1", "2", "3", ....

In other words, there is no reason to use tostring on line 24 -- you want the number i, so use just i.

Similarly, since MainSlides is a list, getNumTabs(MainSlides) will just be the length of MainSlides, or #MainSlides.

for i = 1, #tab do
    local currentTab = tab[i]

Usually, it's better to use ipairs than direction iteration like this:

for _, currentTab in ipairs(tab) do
    if currentTab[2] ~= then
Thanks bro. User#5689 0 — 5y

Answer this question