My goal for this script is so that it will pick a random song from the table from a folder inside of ServerStorage using math.random but when I try it, it spits out this error: attempt to index nil with 'SoundId'
I think the sounds I put inside of ServerStorage ARE sounds
Script:
local MusicFolder = game:GetService("ServerStorage").Music
local songs = {
TheGreatStrategy = MusicFolder:FindFirstChild("TheGreatStrategy"),
Candyland = MusicFolder:FindFirstChild("Candyland"),
Gaiety = MusicFolder:FindFirstChild("Gaiety")
}
wait(1)
local PlayerSound = Instance.new("Sound")
PlayerSound.Parent = game.Workspace
PlayerSound.Name = "SOUNDPLAYER"
while true do
local currentsong = songs[math.random(1, 3)]
local playingsong = currentsong.SoundId
wait(3)
PlayerSound.SoundId = playingsong
PlayerSound:Play()
task.wait(PlayerSound.TimeLength)
end
Or you wouldn’t even need the table in the first place, you could also do this.
local songs = MusicFolder:GetChildren()
local RandomSound = songs[math.random(1,#songs)]
local SoundName = RandomSound.Name
local SoundId = RandomSound.SoundId