boombox
Key Required

boombox

zpez30zepeteg's PlaceDitcailonmemayDitcailonmemay 323 views 10.1K executesUpdated Jul 30, 2026
Unrated
00
Lua Script•418 lines (13599 chars)
local Players = game:GetService("Players")
local UserInputService = game:GetService("UserInputService")

local LocalPlayer = Players.LocalPlayer
local PlayerGui = LocalPlayer:WaitForChild("PlayerGui")

if PlayerGui:FindFirstChild("BoomboxGui") then
    PlayerGui.BoomboxGui:Destroy()
end

local existingSound = LocalPlayer:WaitForChild("PlayerScripts"):FindFirstChild("BoomboxSound")
if existingSound then
    existingSound:Stop()
    existingSound:Destroy()
end

-- Sound Setup
local Sound = Instance.new("Sound")
Sound.Name = "BoomboxSound"
Sound.Looped = true
Sound.Volume = 0.5
Sound.PlaybackSpeed = 1
Sound.Parent = LocalPlayer:WaitForChild("PlayerScripts")

-- ScreenGui
local ScreenGui = Instance.new("ScreenGui")
ScreenGui.Name = "BoomboxGui"
ScreenGui.ResetOnSpawn = false
ScreenGui.Parent = PlayerGui

-- Main Toggle Button
local ToggleBtn = Instance.new("TextButton")
ToggleBtn.Name = "ToggleBtn"
ToggleBtn.Size = UDim2.new(0, 120, 0, 40)
ToggleBtn.Position = UDim2.new(0.05, 0, 0.4, 0)
ToggleBtn.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
ToggleBtn.BorderSizePixel = 0
ToggleBtn.Text = "Boombox"
ToggleBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
ToggleBtn.TextSize = 14
ToggleBtn.Font = Enum.Font.SourceSansBold
ToggleBtn.Parent = ScreenGui

local ToggleUICorner = Instance.new("UICorner")
ToggleUICorner.CornerRadius = UDim.new(0, 8)
ToggleUICorner.Parent = ToggleBtn

-- Main Frame (Tăng chiều cao lên 330 để vừa thanh Speed)
local MainFrame = Instance.new("Frame")
MainFrame.Name = "MainFrame"
MainFrame.Size = UDim2.new(0, 260, 0, 330)
MainFrame.Position = UDim2.new(0.5, -130, 0.5, -165)
MainFrame.BackgroundColor3 = Color3.fromRGB(25, 25, 25)
MainFrame.BorderSizePixel = 0
MainFrame.Visible = false
MainFrame.Parent = ScreenGui

local FrameUICorner = Instance.new("UICorner")
FrameUICorner.CornerRadius = UDim.new(0, 10)
FrameUICorner.Parent = MainFrame

-- Close Button (X)
local CloseBtn = Instance.new("TextButton")
CloseBtn.Name = "CloseBtn"
CloseBtn.Size = UDim2.new(0, 30, 0, 30)
CloseBtn.Position = UDim2.new(1, -35, 0, 5)
CloseBtn.BackgroundTransparency = 1
CloseBtn.Text = "X"
CloseBtn.TextColor3 = Color3.fromRGB(255, 85, 85)
CloseBtn.TextSize = 18
CloseBtn.Font = Enum.Font.SourceSansBold
CloseBtn.Parent = MainFrame

-- ID Input
local IdInput = Instance.new("TextBox")
IdInput.Name = "IdInput"
IdInput.Size = UDim2.new(0, 200, 0, 35)
IdInput.Position = UDim2.new(0.5, -100, 0.12, 0)
IdInput.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
IdInput.BorderSizePixel = 0
IdInput.PlaceholderText = "Enter Sound ID..."
IdInput.Text = ""
IdInput.TextColor3 = Color3.fromRGB(255, 255, 255)
IdInput.TextSize = 14
IdInput.Font = Enum.Font.SourceSans
IdInput.ClearTextOnFocus = false
IdInput.Parent = MainFrame

local InputUICorner = Instance.new("UICorner")
InputUICorner.CornerRadius = UDim.new(0, 6)
InputUICorner.Parent = IdInput

-- Play/Pause Button
local PlayBtn = Instance.new("TextButton")
PlayBtn.Name = "PlayBtn"
PlayBtn.Size = UDim2.new(0, 95, 0, 35)
PlayBtn.Position = UDim2.new(0.5, -100, 0.26, 0)
PlayBtn.BackgroundColor3 = Color3.fromRGB(0, 170, 127)
PlayBtn.BorderSizePixel = 0
PlayBtn.Text = "Play"
PlayBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
PlayBtn.TextSize = 14
PlayBtn.Font = Enum.Font.SourceSansBold
PlayBtn.Parent = MainFrame

local PlayUICorner = Instance.new("UICorner")
PlayUICorner.CornerRadius = UDim.new(0, 6)
PlayUICorner.Parent = PlayBtn

-- Stop All Button
local StopBtn = Instance.new("TextButton")
StopBtn.Name = "StopBtn"
StopBtn.Size = UDim2.new(0, 95, 0, 35)
StopBtn.Position = UDim2.new(0.5, 5, 0.26, 0)
StopBtn.BackgroundColor3 = Color3.fromRGB(200, 50, 50)
StopBtn.BorderSizePixel = 0
StopBtn.Text = "Stop All"
StopBtn.TextColor3 = Color3.fromRGB(255, 255, 255)
StopBtn.TextSize = 14
StopBtn.Font = Enum.Font.SourceSansBold
StopBtn.Parent = MainFrame

local StopUICorner = Instance.new("UICorner")
StopUICorner.CornerRadius = UDim.new(0, 6)
StopUICorner.Parent = StopBtn

----------------------------------------------------
-- VOLUME SYSTEM
----------------------------------------------------
local VolumeLabel = Instance.new("TextLabel")
VolumeLabel.Name = "VolumeLabel"
VolumeLabel.Size = UDim2.new(0, 200, 0, 20)
VolumeLabel.Position = UDim2.new(0.5, -100, 0.42, 0)
VolumeLabel.BackgroundTransparency = 1
VolumeLabel.Text = "Volume: 50%"
VolumeLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
VolumeLabel.TextSize = 13
VolumeLabel.Font = Enum.Font.SourceSans
VolumeLabel.Parent = MainFrame

local SliderBack = Instance.new("Frame")
SliderBack.Name = "SliderBack"
SliderBack.Size = UDim2.new(0, 200, 0, 10)
SliderBack.Position = UDim2.new(0.5, -100, 0.50, 0)
SliderBack.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
SliderBack.BorderSizePixel = 0
SliderBack.Parent = MainFrame

local SliderBackCorner = Instance.new("UICorner")
SliderBackCorner.CornerRadius = UDim.new(0, 5)
SliderBackCorner.Parent = SliderBack

local SliderFill = Instance.new("Frame")
SliderFill.Name = "SliderFill"
SliderFill.Size = UDim2.new(0.5, 0, 1, 0)
SliderFill.BackgroundColor3 = Color3.fromRGB(0, 170, 127)
SliderFill.BorderSizePixel = 0
SliderFill.Parent = SliderBack

local SliderFillCorner = Instance.new("UICorner")
SliderFillCorner.CornerRadius = UDim.new(0, 5)
SliderFillCorner.Parent = SliderFill

----------------------------------------------------
-- SPEED SNAP SYSTEM (X1, X1.5, X2, X2.5, X3)
----------------------------------------------------
local SpeedLabel = Instance.new("TextLabel")
SpeedLabel.Name = "SpeedLabel"
SpeedLabel.Size = UDim2.new(0, 200, 0, 20)
SpeedLabel.Position = UDim2.new(0.5, -100, 0.60, 0)
SpeedLabel.BackgroundTransparency = 1
SpeedLabel.Text = "Speed: x1"
SpeedLabel.TextColor3 = Color3.fromRGB(200, 200, 200)
SpeedLabel.TextSize = 13
SpeedLabel.Font = Enum.Font.SourceSans
SpeedLabel.Parent = MainFrame

local SpeedBack = Instance.new("Frame")
SpeedBack.Name = "SpeedBack"
SpeedBack.Size = UDim2.new(0, 200, 0, 10)
SpeedBack.Position = UDim2.new(0.5, -100, 0.68, 0)
SpeedBack.BackgroundColor3 = Color3.fromRGB(45, 45, 45)
SpeedBack.BorderSizePixel = 0
SpeedBack.Parent = MainFrame

local SpeedBackCorner = Instance.new("UICorner")
SpeedBackCorner.CornerRadius = UDim.new(0, 5)
SpeedBackCorner.Parent = SpeedBack

local SpeedFill = Instance.new("Frame")
SpeedFill.Name = "SpeedFill"
SpeedFill.Size = UDim2.new(0, 0, 1, 0)
SpeedFill.BackgroundColor3 = Color3.fromRGB(0, 150, 255)
SpeedFill.BorderSizePixel = 0
SpeedFill.Parent = SpeedBack

local SpeedFillCorner = Instance.new("UICorner")
SpeedFillCorner.CornerRadius = UDim.new(0, 5)
SpeedFillCorner.Parent = SpeedFill

-- Danh sách các nấc Speed cố định
local speedValues = {1, 1.5, 2, 2.5, 3}
local speedRatios = {0, 0.25, 0.5, 0.75, 1} -- Tương ứng tỷ lệ 0%, 25%, 50%, 75%, 100%

-- Tạo các vạch/khe (Tick Marks) & Text hiển thị nấc
for i, ratio in ipairs(speedRatios) do
    local Notch = Instance.new("Frame")
    Notch.Name = "Notch_" .. tostring(speedValues[i])
    Notch.Size = UDim2.new(0, 2, 0, 14)
    Notch.Position = UDim2.new(ratio, -1, 0.5, -7)
    Notch.BackgroundColor3 = Color3.fromRGB(180, 180, 180)
    Notch.BorderSizePixel = 0
    Notch.ZIndex = 2
    Notch.Parent = SpeedBack

    local NotchText = Instance.new("TextLabel")
    NotchText.Name = "NotchText"
    NotchText.Size = UDim2.new(0, 30, 0, 15)
    NotchText.Position = UDim2.new(ratio, -15, 1, 4)
    NotchText.BackgroundTransparency = 1
    NotchText.Text = "x" .. tostring(speedValues[i])
    NotchText.TextColor3 = Color3.fromRGB(150, 150, 150)
    NotchText.TextSize = 11
    NotchText.Font = Enum.Font.SourceSans
    NotchText.Parent = SpeedBack
end

----------------------------------------------------
-- LOGIC HANDLERS
----------------------------------------------------

local isPlaying = false

local function stopSound()
    Sound:Stop()
    isPlaying = false
    PlayBtn.Text = "Play"
    PlayBtn.BackgroundColor3 = Color3.fromRGB(0, 170, 127)
end

-- Play / Pause Click
PlayBtn.MouseButton1Click:Connect(function()
    local text = IdInput.Text
    local soundId = text:match("%d+")
    
    if isPlaying then
        Sound:Pause()
        isPlaying = false
        PlayBtn.Text = "Play"
        PlayBtn.BackgroundColor3 = Color3.fromRGB(0, 170, 127)
    else
        if soundId then
            Sound:Stop()
            Sound.SoundId = "rbxassetid://" .. soundId
            Sound.TimePosition = 0
            Sound:Play()
            
            isPlaying = true
            PlayBtn.Text = "Pause"
            PlayBtn.BackgroundColor3 = Color3.fromRGB(220, 80, 80)
        end
    end
end)

-- Stop Button Click
StopBtn.MouseButton1Click:Connect(function()
    stopSound()
end)

-- Volume Dragging
local isDraggingVolume = false

local function updateVolume(input)
    local sliderPos = SliderBack.AbsolutePosition.X
    local sliderWidth = SliderBack.AbsoluteSize.X
    local mousePos = input.Position.X
    
    local relativeX = math.clamp(mousePos - sliderPos, 0, sliderWidth)
    local volumeRatio = relativeX / sliderWidth
    
    SliderFill.Size = UDim2.new(volumeRatio, 0, 1, 0)
    Sound.Volume = volumeRatio * 2
    VolumeLabel.Text = "Volume: " .. math.floor(volumeRatio * 100) .. "%"
end

SliderBack.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        isDraggingVolume = true
        updateVolume(input)
    end
end)

-- Speed Dragging & Snap Logic
local isDraggingSpeed = false

local function updateSpeedVisual(input)
    local sliderPos = SpeedBack.AbsolutePosition.X
    local sliderWidth = SpeedBack.AbsoluteSize.X
    local mousePos = input.Position.X
    
    local relativeX = math.clamp(mousePos - sliderPos, 0, sliderWidth)
    local currentRatio = relativeX / sliderWidth
    
    SpeedFill.Size = UDim2.new(currentRatio, 0, 1, 0)
end

local function applySpeedSnap(input)
    local sliderPos = SpeedBack.AbsolutePosition.X
    local sliderWidth = SpeedBack.AbsoluteSize.X
    local mousePos = input.Position.X
    
    local relativeX = math.clamp(mousePos - sliderPos, 0, sliderWidth)
    local currentRatio = relativeX / sliderWidth
    
    -- Tìm nấc gần nhất với vị trí thả tay
    local closestIndex = 1
    local minDistance = math.abs(currentRatio - speedRatios[1])
    
    for i = 2, #speedRatios do
        local dist = math.abs(currentRatio - speedRatios[i])
        if dist < minDistance then
            minDistance = dist
            closestIndex = i
        end
    end
    
    -- Tự động nhảy (Snap) tới nấc đó
    local targetRatio = speedRatios[closestIndex]
    local targetSpeed = speedValues[closestIndex]
    
    SpeedFill.Size = UDim2.new(targetRatio, 0, 1, 0)
    Sound.PlaybackSpeed = targetSpeed
    SpeedLabel.Text = "Speed: x" .. tostring(targetSpeed)
end

SpeedBack.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        isDraggingSpeed = true
        updateSpeedVisual(input)
    end
end)

UserInputService.InputChanged:Connect(function(input)
    if isDraggingVolume and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
        updateVolume(input)
    elseif isDraggingSpeed and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
        updateSpeedVisual(input)
    end
end)

UserInputService.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        if isDraggingVolume then
            isDraggingVolume = false
        end
        if isDraggingSpeed then
            isDraggingSpeed = false
            applySpeedSnap(input) -- Khi thả tay ra sẽ kích hoạt tự dính nấc
        end
    end
end)

-- Close Button
CloseBtn.MouseButton1Click:Connect(function()
    MainFrame.Visible = false
end)

-- Hold to Drag & Click to Toggle
local pressStartTime = 0
local isHolding = false
local dragging = false
local dragStart = nil
local startPos = nil

ToggleBtn.InputBegan:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        pressStartTime = tick()
        isHolding = true
        dragStart = input.Position
        startPos = ToggleBtn.Position
        
        task.spawn(function()
            task.wait(4.5)
            if isHolding then
                dragging = true
                ToggleBtn.BackgroundColor3 = Color3.fromRGB(100, 100, 255)
            end
        end)
    end
end)

UserInputService.InputChanged:Connect(function(input)
    if dragging and (input.UserInputType == Enum.UserInputType.MouseMovement or input.UserInputType == Enum.UserInputType.Touch) then
        local delta = input.Position - dragStart
        ToggleBtn.Position = UDim2.new(
            startPos.X.Scale, 
            startPos.X.Offset + delta.X, 
            startPos.Y.Scale, 
            startPos.Y.Offset + delta.Y
        )
    end
end)

ToggleBtn.InputEnded:Connect(function(input)
    if input.UserInputType == Enum.UserInputType.MouseButton1 or input.UserInputType == Enum.UserInputType.Touch then
        local holdDuration = tick() - pressStartTime
        isHolding = false
        
        if dragging then
            dragging = false
            ToggleBtn.BackgroundColor3 = Color3.fromRGB(35, 35, 35)
        else
            if holdDuration < 4.5 then
                MainFrame.Visible = not MainFrame.Visible
            end
        end
    end
end)

Features & Information

Turn music on/off (visual), adjust volume, speed up. If an error occurs while music is playing and you press Boombox again, press the "Stop All" button.

Community Comments (0)

No comments yet for this script.