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)
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!
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