Need help with Music script

How can I do it that local Music is listed in another script? (An extra script with only the music IDs)

local Music = {
	5108618911,
	159152899,
	913576320,
	158001900,
	2007907591,
	2007907591
}

local chosen = Music[math.random(1, #Music)]
sound.SoundId = "rbxassetid://" .. chosen
wait(0.5)
sound:Play()

You should try using Module as a storage for music ids

3 Likes

How do you mean? Im a Builder and not a scripter xD

1 Like

I’m a little confused, what’s wrong with your script?

The scrip works but I want that the music ids are in a extra script

Oh my bad erm here let me show you how it’s done
Screen Shot 2563-10-19 at 23.52.57

-- Module Script
local Module = {
	
	123456789;
	987654321;
	456456778;
	
}

return Module
-- Local script
local MusicId = require(script.StorageID)
local Chosen = MusicId[math.random(1, #MusicId)]
print(Chosen) --> Random music Id stored within the Module

I suggest you to use the normal code you got there though since it’s a lot more simple than this one

2 Likes

As mentioned earlier, using a module script is best to do this. Add a module script that is parented, create a function with all of your ids, and return the value (your ID).

1 Like