I made a music, playing script, but it does not concatenate properly? The error is attempt to concatenate string with userdata.
local AudioList = { ["ThereItIs"] = 279498364, ["FrostWalts"] = 2037145146, ["LocalForecast"] = 258852901, ["Decisions"] = 337055476, ["Run"] = 1470017017, ["Preposition"] = 257383979, } local ContentProvider = game:GetService("ContentProvider") for name, AudioId in pairs(AudioList) do local AudioInstance = Instance.new("Sound") AudioInstance.SoundId = "rbxassetid://" .. AudioId -- error is here!! AudioInstance.Volume = 0.1 AudioInstance.Name = name AudioInstance.Parent = game.Workspace table.insert(AudioList, AudioInstance) end
The only thing i can think of right now is adding a tostring(AudioId) instead of the raw AudioId so theyre both a string. Try that
It's because you're inserting the audio instance into the table. The table you're looping through will also get updated. Try using a new table or something, the problem is this line though:
table.insert(AudioList, AudioInstance)
I'd do something like this:
local ContentProvider = game:GetService("ContentProvider") local AudioList = { ["ThereItIs"] = 279498364, ["FrostWalts"] = 2037145146, ["LocalForecast"] = 258852901, ["Decisions"] = 337055476, ["Run"] = 1470017017, ["Preposition"] = 257383979, } local audioFiles = {} for name, AudioId in pairs(AudioList) do local AudioInstance = Instance.new("Sound") AudioInstance.SoundId = "rbxassetid://" .. AudioId -- error is here!! AudioInstance.Volume = 0.1 AudioInstance.Name = name AudioInstance.Parent = game.Workspace audioFiles[#audioFiles + 1] = audioInstance end
This should work, just like ChrisTheRobloxPlayYT said, use tostring()
Code:
local AudioList = { ["ThereItIs"] = 279498364, ["FrostWalts"] = 2037145146, ["LocalForecast"] = 258852901, ["Decisions"] = 337055476, ["Run"] = 1470017017, ["Preposition"] = 257383979, } local ContentProvider = game:GetService("ContentProvider") for name, Id in pairs(AudioList) do local AudioInstance = Instance.new("Sound") AudioInstance.SoundId = 'rbxassetid://' .. tostring(Id) -- error is here!! AudioInstance.Volume = 0.1 AudioInstance.Name = name AudioInstance.Parent = game.Workspace table.insert(AudioList, AudioInstance) end
But to prevent creation of the same song multiple times we add it to another table like Psudar said
local AudioList = { ["ThereItIs"] = 279498364, ["FrostWalts"] = 2037145146, ["LocalForecast"] = 258852901, ["Decisions"] = 337055476, ["Run"] = 1470017017, ["Preposition"] = 257383979, } local ContentProvider = game:GetService("ContentProvider") local addedAudio = {} for name, Id in pairs(AudioList) do local AudioInstance = Instance.new("Sound") AudioInstance.SoundId = 'rbxassetid://' .. tostring(Id) -- error is here!! AudioInstance.Volume = 0.1 AudioInstance.Name = name AudioInstance.Parent = game.Workspace table.insert(addedAudio, AudioInstance) end