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

How do I fix this error?

Asked by 9 years ago

I already got this answered, but all of a sudden there was an error that popped up. Here is what I have:

Script:

local bin = script.Parent
local decal = bin.Decal

local MainSlides = {"http://www.roblox.com/asset/?id=154539172", "http://www.roblox.com/asset/?id=177042272",
"http://www.roblox.com/asset/?id=157119414", "http://www.roblox.com/asset/?id=175271294",
"http://www.roblox.com/asset/?id=198632478"}

local SoundsForSlides = {12222030} -- Add more if you wish, will play with the slide

local function runTable(table, delayTime)
    for i=1,#table do
        decal.Texture = table[i]
        wait(math.random(2, 5)) --The time can vary from 2 to 5 seconds.
        if SoundsForSlides[i] then
            SoundsForSlides[i]:Play() --If this doesn't work tell me
        end
    end
end

while wait() do
    runTable(MainSlides, WaitTime)
end

Error

20:30:45.135 - Workspace.Part.SlideScript:15: attempt to index field '?' (a number value)
0
This code doesn't really make sense... Can you explain what you were trying to do with it? BlueTaslem 18071 — 9y
0
I wanted it to play the audio while the slides is going on User#5689 -1 — 9y

2 answers

Log in to vote
1
Answered by 9 years ago

SoundsForSlides is a Number Value, not the actual Audio, but, your attempting to play a Number Value, that is the problem on line 15, however, this can be fixed, by using/creating a Sound type instance, and by setting the SoundId property to the Number Value, let me explain;

local SoundId = 175215264 --'SoundId' is identifying the Number Value '175215264'

local Sound = Instance.new("Sound",game.Workspace) --Identifier 'Sound' is now identifying/specifying the create 'Sound' type instance, and sets it's 'Parent' to 'game.Workspace'
Sound.SoundId = "http://www.roblox.com/asset/?id="..SoundId --This sets identifier 'Sound''s SoundId property to identifier 'SoundId''s Number Value, I added the link because IT IS required, as well as, I have seen it is not require to, but I simply do not trust it, otherwise, failing to add the link, it WILL NOT play, and will result in an error, and saying the Audio does not exist
Sound:Play() --This will play identifier 'Sound' in the Workspace 'Globally'

Hope this helped!

0
Thank you so much bro. User#5689 -1 — 9y
Ad
Log in to vote
1
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
9 years ago

With the'SoundsForSlides' table, you just have an index with an int in it. Then on line 15 when you attempt to index SoundForSlides[i] and use the Play() method on it.. The Play method is a method of the Sound object, not numbers. That's like saying 12222030:Play().

Create a sound object with the SoundId as SoundsForSlides[i]'s id.

local bin = script.Parent
local decal = bin.Decal

local MainSlides = {
"http://www.roblox.com/asset/?id=154539172", 
"http://www.roblox.com/asset/?id=177042272",
"http://www.roblox.com/asset/?id=157119414", 
"http://www.roblox.com/asset/?id=175271294",
"http://www.roblox.com/asset/?id=198632478"
}

local SoundsForSlides = {12222030} -- Add more if you wish, will play with the slide

function playAudio(ID)
    local s = Instance.new('Sound',bin)
    s.SoundId = "http://www.roblox.com/asset/?id="..tostring(ID)
    s:Play()
end

function runTable(table, delayTime)
    for i=1,#table do
        decal.Texture = table[i]
        wait(math.random(2, 5))
        if SoundsForSlides[i] then
            playAudio(SoundsForSlides[i])
        end
    end
end

while wait() do
    runTable(MainSlides, WaitTime)
end

0
Thank you so much bro. User#5689 -1 — 9y

Answer this question