Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How Do I Get This Music Gui To Work With Shorter Audios?

Asked by 6 years ago

I currently use a trello music player with a gui made by wizzy011. It is a fantastic player, the best one I've used so far. The one problem I'm running into with this script is the fact that it has a set wait time of 120 seconds (2 minutes) before the song gets switched. This is a problem because when I go to add a song onto it, there is sometimes a long pause after a song is done because some audios arent 120 seconds long. This really limits the amount of music I can add to this player. There is no loop function implemented into it so I cant just have the shorter audios loop for 2 minutes. I would love to have it made to where it switches the song automatically when the audio is finished but if that Is not possible I would be fine with it looping for 120 seconds aswell. I have in fact tried to add a loop function and failed. Please help. Thank you.

local productId = 26059960 --your dev product for a song

local trelloboard = "yOFBQk6X" -- The id of numbers and letters in the Url. For example https://trello.com/b/h3ORMmQR/music "h3ORMmQR" would be the id.
local songs = {}








-- do not touch anything below or I will cry ~Wiz --

local nowplaying = ""

local requests = {
}

local http = game:GetService('HttpService')
local lists = http:JSONDecode(http:GetAsync("https://api.trello.com/1/boards/"..trelloboard.."/lists"))
for _,v in pairs(lists) do
    if v.name == "Music List" then
        local items = http:JSONDecode(http:GetAsync("https://api.trello.com/1/lists/"..v.id.."/cards"))
        print(#items)
        for _,v in pairs(items) do
            if v.name:match(":") ~= nil then
                local s,f = string.find(v.name,":")
                table.insert(songs, string.sub(v.name,f+1)) 
            end
        end
    end
end

function shuffleTable(t)
    math.randomseed(tick())
    assert(t, "shuffleTable() expected a table, got nil" )
    local iterations = #t
    local j
    for i = iterations, 2, -1 do
        j = math.random(i)
        t[i], t[j] = t[j], t[i]
    end
end

shuffleTable(songs)

local songnum = 0

function game.ReplicatedStorage.musicEvents.getSong.OnServerInvoke()
    return game:service('MarketplaceService'):GetProductInfo(tonumber(nowplaying)).Name
end

game.ReplicatedStorage.musicEvents.purchaseSong.OnServerEvent:connect(function(p)
    if p.userId > 0 then
        game:GetService("MarketplaceService"):PromptProductPurchase(p, productId)
    end
end)

local votes = {

}

function makesong()
    workspace:WaitForChild("TrelloSound"):Stop()
    wait()
    if #requests == 0 then
        songnum = songnum+1
        if songnum > #songs then
            songnum = 1
        end
        nowplaying = songs[songnum]
    else
        nowplaying = requests[1]
        table.remove(requests,1)
    end
    local thisfunctionssong = nowplaying
    workspace.TrelloSound.SoundId = "rbxassetid://"..thisfunctionssong
    wait()
    workspace.TrelloSound:Play()
    game.ReplicatedStorage.musicEvents.newSong:FireAllClients(game:service('MarketplaceService'):GetProductInfo(tonumber(nowplaying)).Name)
    votes = {}
    wait(120)
    if "rbxassetid://"..nowplaying == "rbxassetid://"..thisfunctionssong then
        makesong()
    end
end

function countVotes()
    local c = 0
    for _,v in pairs(votes) do
        if v[2] == true then
            c = c +1
        end
    end
    local remainder = #game.Players:GetPlayers() - #votes
    local percent = (c + (remainder/2))/#game.Players:GetPlayers()
    game.ReplicatedStorage.musicEvents.voteChange:FireAllClients(percent)
    if percent <= 0.2 then
        --skip song
        makesong()
    end
    return
end

game.ReplicatedStorage.musicEvents.voteYes.OnServerEvent:connect(function(p)
    for _,v in pairs(votes) do
        if v[1] == p.Name then
            v[2] = true
            countVotes()
            return
        end
    end
    table.insert(votes, {p.Name, true})
    countVotes()
end)

game.ReplicatedStorage.musicEvents.voteNo.OnServerEvent:connect(function(p)
    for _,v in pairs(votes) do
        if v[1] == p.Name then
            v[2] = false
            countVotes()
            return
        end
    end
    table.insert(votes, {p.Name, false})
    countVotes()
end)

--skip song command

Group = 2888962
RequiredRank = 14
game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(msg)
        if Player:GetRankInGroup(Group) >= RequiredRank or Player.Name == "Player" or Player.Name == "Crossota" or Player.Name == "TimeFailured" or Player.Name == "railworks2" or Player.Name == "ExploreTheLocal" or Player.Name == "Evelynx3" then
            if msg == 'skipsong' or  msg == 'SkipSong' then
                makesong()
            end
        end
    end)
end)

Group = 2888962
RequiredRank = 14
game.Players.PlayerAdded:connect(function(Player)
    Player.Chatted:connect(function(msg)
        if Player:GetRankInGroup(Group) >= RequiredRank or Player.Name == "Player" or Player.Name == "Crossota" or Player.Name == "TimeFailured" or Player.Name == "railworks2" or Player.Name == "ExploreTheLocal" or Player.Name == "Evelynx3" then
            if msg == ':disable' then
                script.Parent.Parent.opt.Song.Text = "System Disabled"
                game.Workspace.TrelloSound.Volume = 0 
            end
        end
    end)
end)

game:GetService('MarketplaceService').ProcessReceipt = function(details)
    for _, player in ipairs(game.Players:GetPlayers()) do
        if player.userId == details.PlayerId then
            if details.ProductId == productId then
                game.ReplicatedStorage.musicEvents.addSong:FireClient(player)
            end
        end 
    end
end

game.ReplicatedStorage.musicEvents.addSong.OnServerEvent:connect(function(p,id)
    if tonumber(id) ~= nil and game:GetService("MarketplaceService"):GetProductInfo(tonumber(id)).AssetTypeId == 3 then
        table.insert(requests, id)
    end
end)

makesong()

1 answer

Log in to vote
0
Answered by 6 years ago

Instead of wait(120) use workspace:WaitForChild("TrelloSound").Ended:wait()

0
Thank you. OVOFinessinq 21 — 6y
Ad

Answer this question