P_YStudio

Change Music Button

Apr 22nd, 2023
1,225
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.52 KB | Source Code | 0 0
  1. local Music = script.Parent.Music:GetChildren()
  2. local CurrentMusicObjectId = 0
  3. local LastSoundObject = nil
  4. script.Parent.MouseButton1Click:Connect(function()
  5.  
  6.     if CurrentMusicObjectId == #Music then
  7.         CurrentMusicObjectId = 1 else CurrentMusicObjectId += 1 end
  8.     game.SoundService:ClearAllChildren()
  9.     if LastSoundObject ~= nil then LastSoundObject:Destroy() end
  10.     local SoundObject = Music[CurrentMusicObjectId]:Clone()
  11.     SoundObject.Parent = game.Workspace
  12.     LastSoundObject = SoundObject
  13.     SoundObject.Playing = true
  14.  
  15. end)
Advertisement
Add Comment
Please, Sign In to add comment