Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- to be placed in StarterPlayer > StarterPlayerScripts
- local Players = game:GetService("Players")
- -- wait for local player PlayerGui
- local LocalPlayer = Players.LocalPlayer
- local playerGui = LocalPlayer:WaitForChild("PlayerGui")
- local PlayerSongEvent = game:GetService("ReplicatedStorage"):FindFirstChild("PlayerSong")
- local function SongSpawner()
- -- create a ScreenGui
- local screenGui = Instance.new("ScreenGui", playerGui)
- screenGui.ResetOnSpawn = false
- -- create a holder for our bar
- local frame = Instance.new("Frame", screenGui)
- frame.AnchorPoint = Vector2.new(0.5, 0.5)
- frame.Position = UDim2.new(0.5, 0, 0.5, 0)
- frame.Size = UDim2.new(0.3, 0, 0.05, 0)
- -- create a bar
- local bar = Instance.new("Frame", frame)
- bar.Position = UDim2.new(0, 0, 0, 0)
- bar.Size = UDim2.new(1, 0, 1, 0)
- bar.BackgroundColor3 = Color3.new(0, 1, 0)
- -- NameText
- local SongName = Instance.new("TextLabel", frame)
- SongName.Name = "SongName"
- SongName.Size = UDim2.new(1,0,1,0)
- SongName.Position = UDim2.new(0,0,-1.2,0)
- SongName.TextScaled = true
- SongName.TextXAlignment = Enum.TextXAlignment.Left
- SongName.BackgroundTransparency = 1
- SongName.TextColor3 = Color3.new(0,0,0)
- SongName.TextStrokeColor3 = Color3.new(255,255,255)
- SongName.TextStrokeTransparency = 0
- SongName.TextTransparency = 1
- SongName.Font = Enum.Font.SourceSansBold
- -- create buttons
- local NextSongButton = Instance.new("ImageButton", screenGui)
- NextSongButton.Position = UDim2.new(0.67, 0, 0.56, 0)
- NextSongButton.Size = UDim2.new(0.025,0,0.05,0)
- NextSongButton.Name = "NextSongButton"
- local NextSongCorner = Instance.new("UICorner", NextSongButton)
- NextSongCorner.CornerRadius = UDim.new(1,0)
- local NextSongBorder = Instance.new("UIStroke", NextSongButton)
- NextSongBorder.Thickness = 2
- NextSongButton.Image = "http://www.roblox.com/asset/?id=5073738924"
- local PreviousSongButton = Instance.new("ImageButton", screenGui)
- PreviousSongButton.Position = UDim2.new(0.3, 0, 0.56, 0)
- PreviousSongButton.Size = UDim2.new(0.025, 0,0.05,0)
- PreviousSongButton.Name = "PreviousSongButton"
- local PreviousSongCorner = Instance.new("UICorner", PreviousSongButton)
- PreviousSongCorner.CornerRadius = UDim.new(1,0)
- local PreviousSongBorder = Instance.new("UIStroke", PreviousSongButton)
- PreviousSongBorder.Thickness = 2
- PreviousSongButton.Image = "http://www.roblox.com/asset/?id=5073738924"
- PreviousSongButton.ImageRectOffset = Vector2.new(1024,0)
- PreviousSongButton.ImageRectSize = Vector2.new(-1024,1024)
- -- describes what will happen when the song changes?
- local TweenService = game:GetService("TweenService")
- local function TextVisuals(object,text,length)
- local Info = TweenInfo.new(1)
- object.TextTransparency = 1
- local Tween = TweenService:Create(object,Info,{TextTransparency = 0})
- Tween:Play()
- for i = 1,#text,1 do
- object.Text = string.sub(text,1,i)
- wait(length)
- end
- task.wait(2)
- local Tween2 = TweenService:Create(object,Info,{TextTransparency = 1})
- Tween2:Play()
- end
- local SongChange = true
- NextSongButton.MouseButton1Up:Connect(function()
- -- print("fired")
- if SongChange == true then
- SongChange = false
- for i,songs in pairs(LocalPlayer.PlayerGui:WaitForChild("LocalSounds"):GetChildren()) do
- print(songs)
- if songs.IsPlaying == true then
- songs:Stop()
- else
- end
- end
- SongChange = true
- end
- end)
- -- create a sound
- --local sound = Instance.new("Sound", screenGui)
- --sound.SoundId = "rbxassetid://1838673350"
- --sound.Looped = true
- --sound:Play()
- local Value = 1
- local SoundsFolder = LocalPlayer.PlayerGui:WaitForChild("LocalSounds"):GetChildren()
- print(SoundsFolder[Value])
- local sound = SoundsFolder[Value]:Play()
- PreviousSongButton.MouseButton1Up:Connect(function()
- if SongChange == true then
- SongChange = false
- for i,songs in pairs(LocalPlayer.PlayerGui:WaitForChild("LocalSounds"):GetChildren()) do
- if songs.IsPlaying == true then
- if Value > 1 then --and Value ~= 2
- print("Value is greather than 1")
- if Value == 2 then
- Value = #SoundsFolder - 1
- songs:Stop()
- else
- Value = Value - 2
- songs:Stop()
- end
- elseif Value == 0 then
- print("Value is smaller than 1")
- songs:Stop()
- Value = #SoundsFolder - 1
- --Value = 4
- end
- end
- end
- SongChange = true
- end
- end)
- --[[for i = 1, #SoundsFolder do
- local child = SoundsFolder[i]
- print(child.Name .. " is child number " .. i)
- end--]]
- --local sound = SoundsFolder[Value]--+ 1
- --print(sound.Name)
- -- define a max loudness
- local maxLoudness = 475
- local debounce = true
- local SongsNumber = #SoundsFolder
- -- animate the amplitude bar
- print(#SoundsFolder)
- task.wait(1)
- game:GetService("RunService").RenderStepped:Connect(function()
- if SoundsFolder[Value].IsPlaying == false and debounce then --and not debounce--sound.TimeLength >= sound.TimePosition - 1
- debounce = false
- print("debounce got false")
- print(Value)
- if Value >= SongsNumber then
- Value = 1
- -- sound:Play()
- print(Value)
- task.wait(.1)
- local sound = SoundsFolder[Value]:Play()
- TextVisuals(SongName,"Playing: " ..SoundsFolder[Value].Name ,0.05)
- debounce = true
- else
- if Value < SongsNumber and not debounce then -- and debounce == true
- --debounce = true
- -- if Value == 0 then
- -- Value = 1
- -- end
- print(#SoundsFolder)
- print(tonumber(Value == SongsNumber))
- --print(tonumber(#SoundsFolder == Value))
- task.wait(1)
- Value = Value + 1
- print(Value)
- print(SoundsFolder[Value])
- --sound:Stop()
- local sound = SoundsFolder[Value]:Play()
- TextVisuals(SongName,"Playing: " ..SoundsFolder[Value].Name ,0.05)
- -- sound:Play()
- -- return
- -- SoundsFolder[Value]:Play()
- --debounce = true
- end
- debounce = true
- end
- else --sound
- -- print("playing")
- local amplitude = math.clamp(SoundsFolder[Value].PlaybackLoudness / maxLoudness, 0, 1)
- bar.Size = UDim2.new(amplitude, 0, 1, 0)
- -- print("TimeLength".. SoundsFolder[Value].TimeLength,"TimePosition".. SoundsFolder[Value].TimePosition) -- time and position check!!
- --print(sound.PlaybackLoudness)
- if SoundsFolder[Value].PlaybackLoudness >= 475 then
- bar.BackgroundColor3 = Color3.new(1, 0, 0)
- else
- bar.BackgroundColor3 = Color3.new(0, 1, 0)
- end
- end
- end)
- end
- SongSpawner()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement