I have an SCP game project. In SCP CB random announcements happen randomly so. How do I make random music play randomly can I get a script or something and if someone does where do I put the script and is it a local script or script or module script
Alright so one way you can achieve this is by having an array of different sounds,
local Sounds = { "rbxassetid://5706135664", "rbxassetid://5706135664", "rbxassetid://5706135664" } --obviously not all of these are gonna have the same ID just replace them with whatever ID's you have
So now that we have a table of all the sound effects that you want to play choosing a random one is very simple, you can just use the math.random function in order to get a random index.
local SoundIndex = math.random(1,3) --this would choose a random number between 1 and 3
Obviously you'd change it from 1,3 to whatever your minimum/maximum is depending on how many sound effects you have, and then after you have gotten your random index you can just create a sound object the normal way you usually do, but this time for the SoundID you'd want to use the table and reference the index from math.random so it'd look something like this
local Sound = Instance.new("Sound") --instance or create the sound object Sound.Parent = game.Workspace.part --set its parent Sound.SoundId = Sounds[SoundIndex] --and finally use the random index so that your Sound:Play()
So once you have all that done, the script should look something like this (Please don't just copy the script, try to read what I said before as it will be more beneficial to you in the long run.)
local Sounds = { "rbxassetid://5706135664", "rbxassetid://5706135664", "rbxassetid://5706135664" } --obviously not all of these are gonna have the same ID just replace them with whatever ID's you have local SoundIndex = math.random(1,3) --this would choose a random number between 1 and 3 local Sound = Instance.new("Sound") --instance or create the sound object Sound.Parent = game.Workspace.part --set its parent Sound.SoundId = Sounds[SoundIndex] --and finally use the random index so that your Sound:Play()