JIT
making your audio player code more customizable
this code. local Players = game:GetService("Players") local ReplicatedStorage = game:GetService("ReplicatedStorage") local Workspace = game:GetService("Workspace") local timerStatusEvent = ReplicatedStorage:WaitForChild("TimerStatusEvent") local audioList = { Groups = { { Name = "Main OST (Tiyu Collection)", Looped = false, Tracks = { {Id = "rbxassetid://94742244206418", Title = "00 tutorial", Creator = "tiyu", Include = true}, {Id = "rbxassetid://136885519406038", Title = "01 home", Creator = "tiyu", Include = true}, {Id = "rbxassetid://119800075688581", Title = "02 outside", Creator = "tiyu", Include = true}, {Id = "rbxassetid://87603947652794", Title = "03 friend or foe?", Creator = "tiyu", Include = true}, {Id = "rbxassetid://120669588571217", Title = "04 woods", Creator = "tiyu", Include = true}, {Id = "rbxassetid://136737623977251", Title = "06 are we in space now?", Creator = "tiyu", Include = true}, {Id = "rbxassetid://135838999900642", Title = "08 and life goes on...", Creator = "tiyu", Include = true}, {Id = "rbxassetid://104924170057536", Title = "stalemate", Creator = "tiyu", Include = true}, {Id = "rbxassetid://94132726991055", Title = "sugar rush", Creator = "tiyu", Include = true}, {Id = "rbxassetid://100610468670002", Title = "another summer...", Creator = "tiyu", Include = true} }}, { Name = "JetDarc Collection", Looped = false, Tracks = { {Id = "rbxassetid://93204529310180", Title = "Awakening", Creator = "JetDarc", Include = true}, {Id = "rbxassetid://84485409731242", Title = "Deep Green Overgrowth", Creator = "JetDarc", Include = true}, {Id = "rbxassetid://127960275435157", Title = "HUH?? EGYPTIAN JAM???", Creator = "JetDarc", Include = true}, {Id = "rbxassetid://78760811458606", Title = "Land of Wyverns", Creator = "JetDarc", Include = true}, {Id = "rbxassetid://139269407416756", Title = "Acid Factory", Creator = "JetDarc", Include = true}, {Id = "rbxassetid://103178187421839", Title = "Glitter Star", Creator = "JetDarc", Include = true}, {Id = "rbxassetid://109771381087989", Title = "Mystical Area", Creator = "JetDarc", Include = true} }}, { Name = "Escape Sequence Track", Looped = true , Tracks = { {Id = "rbxassetid://110312226164806", Title = "07 the battle to save the world or whatever", Creator = "tiyu", Include = false} }}, { Name = "Overtime Track", Looped = true, Tracks = { {Id = "rbxassetid://73204364043577", Title = "RUN!", Creator = "JUST RUN!", Include = false} }}, { Name = "?", Looped = true, Tracks = { {Id = "rbxassetid://0", Title = "?", Creator = "?", Include = false} }}, } } local currentAudio = nil local isMuted = false local muteButton local currentGroupIndex = 1 local switchButton = nil local previousGroupIndex = currentGroupIndex local trackIndices = { [1] = 1, [2] = 1, [3] = 1, [4] = 1, [5] = 1 } local textLabel local function clearGui() local gui = Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("AudioListGui") if gui then gui:Destroy() end end local function playAudioGroup(groupIndex) if groupIndex == nil then if currentAudio then currentAudio:Stop() currentAudio:Destroy() currentAudio = nil end if textLabel then textLabel.Text = "" end return end local gui = Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("AudioListGui") if not gui then return end local barFrame = gui:FindFirstChildWhichIsA("Frame") textLabel = barFrame and barFrame:FindFirstChildWhichIsA("TextLabel") local groupData = audioList.Groups[groupIndex] if not groupData or not groupData.Tracks then if textLabel then textLabel.Text = "blank - blank" end return end local selectedGroup = groupData.Tracks if trackIndices[groupIndex] > #selectedGroup then trackIndices[groupIndex] = 1 end if currentAudio then currentAudio:Stop() currentAudio:Destroy() end local index = trackIndices[groupIndex] local track = selectedGroup[index] if not track then if textLabel then textLabel.Text = " - " end return end currentAudio = Instance.new("Sound") currentAudio.SoundId = track.Id currentAudio.Parent = Workspace currentAudio:Play() if isMuted then currentAudio.Volume = 0 end if textLabel then textLabel.Text = track.Title .. " - " .. track.Creator end local gui = Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("AudioListGui") if gui then local barFrame = gui:FindFirstChildWhichIsA("Frame") local groupLabel = barFrame and barFrame:FindFirstChild("GroupLabel") if groupLabel then groupLabel.Text = "Album - " .. (groupData.Name or "Unknown") end end currentAudio.Ended:Connect(function() local loopSameTrack = groupData.Looped if loopSameTrack then task.wait(0.01) playAudioGroup(groupIndex) else -- cycle to next trackIndices[groupIndex] = (index % #selectedGroup) + 1 playAudioGroup(groupIndex) end end) end local function createSwitchButton(barFrame) if switchButton then switchButton:Destroy() end switchButton = Instance.new("TextButton") switchButton.Size = UDim2.new(0, 155, 0, 25) -- Match mute button height switchButton.Position = UDim2.new(0, 100, 0, 5) -- Match vertical alignment with mute switchButton.Text = "Switch to Album 2" switchButton.TextSize = 13 -- Match mute button text size switchButton.Font = Enum.Font.GothamBold -- Match mute button font switchButton.TextColor3 = Color3.fromRGB(255, 255, 255) switchButton.BackgroundColor3 = Color3.fromRGB(40, 40, 40) -- Match mute button color switchButton.BorderSizePixel = 0 -- Match mute button border switchButton.Parent = barFrame switchButton.MouseButton1Click:Connect(function() if currentGroupIndex == 2 then currentGroupIndex = 1 switchButton.Text = "Switch to Album 2" else currentGroupIndex = 2 switchButton.Text = "Switch to Album 1" end previousGroupIndex = currentGroupIndex playAudioGroup(currentGroupIndex) end) end local function setupGui() clearGui() local screenGui = Instance.new("ScreenGui") screenGui.Name = "AudioListGui" screenGui.Parent = Players.LocalPlayer:WaitForChild("PlayerGui") local barFrame = Instance.new("Frame") barFrame.Size = UDim2.new(1, 0, 0, 35) barFrame.Position = UDim2.new(0, 0, 0, 0) barFrame.BackgroundColor3 = Color3.fromRGB(10, 10, 10) barFrame.BackgroundTransparency = 0.25 barFrame.BorderSizePixel = 0 barFrame.Parent = screenGui local groupLabel = Instance.new("TextLabel") groupLabel.Name = "GroupLabel" groupLabel.Size = UDim2.new(0, 300, 1, 0) groupLabel.Position = UDim2.new(1, -310, 0, 0) groupLabel.BackgroundTransparency = 1 groupLabel.TextColor3 = Color3.fromRGB(180, 180, 255) groupLabel.TextSize = 15 groupLabel.Font = Enum.Font.GothamBold groupLabel.TextXAlignment = Enum.TextXAlignment.Right groupLabel.Text = "Album - ???" groupLabel.Parent = barFrame muteButton = Instance.new("TextButton") muteButton.Size = UDim2.new(0, 80, 0, 25) muteButton.Position = UDim2.new(0, 10, 0, 5) muteButton.Text = "Mute" muteButton.TextSize = 13 muteButton.Font = Enum.Font.GothamBold muteButton.TextColor3 = Color3.fromRGB(255, 255, 255) muteButton.BackgroundColor3 = Color3.fromRGB(40, 40, 40) muteButton.BorderSizePixel = 0 muteButton.Parent = barFrame muteButton.MouseButton1Click:Connect(function() if isMuted then if currentAudio then currentAudio.Volume = 1 end muteButton.Text = "Mute" else if currentAudio then currentAudio.Volume = 0 end muteButton.Text = "Unmute" end isMuted = not isMuted end) createSwitchButton(barFrame) playAudioGroup(currentGroupIndex) end local function onCharacterAdded() setupGui() if not isMuted and currentAudio then currentAudio.Volume = 0.5 end end Players.LocalPlayer.CharacterAdded:Connect(onCharacterAdded) if Players.LocalPlayer.Character then onCharacterAdded() end timerStatusEvent.OnClientEvent:Connect(function(isActive, isSecondActive) local gui = Players.LocalPlayer:FindFirstChild("PlayerGui"):FindFirstChild("AudioListGui") if not gui then return end local barFrame = gui:FindFirstChildWhichIsA("Frame") if isActive then previousGroupIndex = currentGroupIndex currentGroupIndex = isSecondActive and 4 or 3 if currentAudio then currentAudio:Stop() end if switchButton then switchButton.Visible = false end playAudioGroup(currentGroupIndex) else if currentGroupIndex == 3 then if currentAudio then currentAudio:Stop() currentAudio:Destroy() currentAudio = nil end if textLabel then textLabel.Text = "" end end if previousGroupIndex == 3 then previousGroupIndex = 1 end currentGroupIndex = previousGroupIndex if switchButton then switchButton.Visible = true end playAudioGroup(currentGroupIndex) end end) -- Expose music stop method globally for other scripts local function forceStopMusic() currentGroupIndex = nil playAudioGroup(nil) end _G.ForceStopMusic = forceStopMusic make it 10x more customizable
Updated files
v1