Hello,
I’m currently working on a music playing system and I’m trying to make a visual tracker for the currently playing song. I’m working on the script that moves the tracker along the line according to the length of the song, but I don’t know how to go about it, HELP. The song is a sound object in the Workspace that gets updated to play a different song from a playlist stored in a table. I want the tracker to move along the line according to the length of the song, and to reset when a new song starts playing.
- Here is the song playing script:
local Players = game:GetService("Players")
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local updateSong = ReplicatedStorage.UpdateSong
local sound = {game.Workspace:WaitForChild("BackgroundMusic")}
local ContentProvider = game:GetService("ContentProvider")
local playlist = {
["Barbie and 12 Dancing Princesses Theme Song - Barbie"] = "rbxassetid://4614145040",
["Brandenburg Concerto #3, Allegro - Johann Sebastian Bach"] = "rbxassetid://1848052559",
["Follow Your Dreams (Piano) - Sheryn Regis"] = "rbxassetid://1839680736",
["Gymnopdie No 1 - Erik Satie"] = "rbxassetid://6163865135",
["Lavender Blue - Dilly Dilly"] = "rbxassetid://1847584954",
["Moonlight Sonata (Solo Piano) - Beethoven"] = "rbxassetid://1838577407",
["Once Upon A December (Piano) - Emile Pandolfi"] = "rbxassetid://313981815",
["Prelude No. 4 - Debussy"] = "rbxassetid://515792175",
["Swan Lake - Barbie"] = "rbxassetid://6072424146",
["Symphony No 6 Pastorale In F Major, Op 68 - Beethoven"] = "rbxassetid://1844267333"} --Playlist
local function getKeyFromValue(tab, input)--tab is the table and input is the value that you're looking for the key.
for key, value in pairs(tab) do
if value == input then
return key
end
end
end
Players.PlayerAdded:Connect(function(player)--Updating the song playing for when a player joins.
updateSong:FireClient(player, getKeyFromValue(playlist, sound[1].SoundId), sound[1])
end)
while true do
for i, v in pairs(playlist) do
sound[1].SoundId = v
ContentProvider:PreloadAsync(sound, print("Loaded Song")) --Loading buttons volume image
updateSong:FireAllClients(i, sound[1])--This is where the server must update everyone's GUI's
sound[1]:Play()
sound[1].Ended:Wait()
end
end
- Here is the current song and song length local script:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local updateSong = ReplicatedStorage.UpdateSong
local TFM = require(ReplicatedStorage.TFM)
local songNameLabel = script.Parent:WaitForChild("SongNameLabel")
local songLengthEnd = script.Parent:WaitForChild("SongLengthEnd")
updateSong.OnClientEvent:Connect(function(songName, songLength)
songNameLabel.Text = songName
songLengthEnd.Text = TFM:Convert(math.floor(songLength), 'Default', true)
end)
- Here is the explorer showing the two gui’s the line and the tracker:
- Here is a really embarrasing atempt at making the tracker work:
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local RunService = game:GetService("RunService")
local TFM = require(ReplicatedStorage.TFM)
local backgroundMusic = game.Workspace:WaitForChild("BackgroundMusic")
local pointer = script.Parent
local songLengthLine = script.Parent.Parent:WaitForChild("SongLengthLine")
local startPosition = UDim2.new(0.389, 0,0.287, 0)
local endPosition = UDim2.new(0.61, 0,0.285, 0)
local lineLength = 0.227
local oldTimePosition = backgroundMusic.TimePosition -- initial
--Script
RunService.RenderStepped:Connect(function()
local incrament = 0.227/backgroundMusic.TimeLength
wait(incrament)
local pos = backgroundMusic.TimePosition
if pos ~= oldTimePosition then
oldTimePosition = pos
pointer.Position = pointer.Position + UDim2.new(incrament,0,0,0)
end
end)
Ask in replies if you want to see other facets of my system.