I'm trying to make random music play in my game. Not a specific order for the music to play just random. I've tried so many different ways and none work I am confusion.
local Ids = {158849566,1238143270,412393959} --id table local Music = workspace.Sound.Music local IdChosen local function RandomId() local Id = math.random(3) --number of ids in table IdChosen = Ids[Id] end RandomId() print(IdChosen) Music.SoundId = "rbxassetid://"..IdChosen Music:Play() Music.Ended:Connect(function(soundid) repeat RandomId() until IdChosen ~= soundid -- makes sure no repeat Music.SoundId = "rbxassetid://"..IdChosen Music:Play() end)
this way sould stop it from repeating a song
local overallmusic = game.Workspace.OverallMusic --this is the sound that will be changed/updated local RunSer = game:GetService("RunService") --checks per frame local music = {} --Just put a sound id in here, make sure to include "," when adding multiple RunSer.Heartbeat:Connect(function() if overallmusic.Playing == false then local musicpick = music[math.random(1,#music)] --this gets a random song from the music table overallmusic.SoundId = "rbxassetid://"..musicpick --applies the chosen song overallmusic.TimePosition = 0 --resets the time overallmusic:Play() end wait() end)
Hope this helps! :)