Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

GUI skip button won't play any music. Why?

I made GUI button that has two skip buttons. When you press forward skip, it plays a song playlist. Inside clickbutton, I added audio which inside of it, I added a script:

	math.randomseed(tick())
02
math.random() -- throw out first not-very-random value (known limitation of lua)
03
 
04
musicTable = --Making a table of music / your songs
05
{
06
    "rbxassetid://142305080",  -- 1 - Let's Groove
07
    "rbxassetid://671389213",  -- 2 - Can't Touch This
08
    "rbxassetid://609246843",  -- 3 - Take on Me
09
    "rbxassetid://1100823134", -- 4 - At Dawn
10
    "rbxassetid://681266896",  -- 5 - Safety Dance
11
    "rbxassetid://323743169",  -- 6 - Working for the Weekend
12
    "rbxassetid://442656036",  -- 7 - Don't you (Forget About Me)
13
    "rbxassetid://706699539",  -- 8 - Beat it
14
    "rbxassetid://838691861"   -- 9 - Hey you, you better keep walking!
15
}
16
 
17
script.Parent.Parent.MouseButton1Click:Connect(function()
18
    while true do
19
        local index = math.random(1, #musicTable - 1)
20
        musicTable[1], musicTable[index] = musicTable[index], musicTable[1]
21
        for i = 2, #musicTable-1 do
22
            index = math.random(i, #musicTable)
23
            musicTable[i], musicTable[index] = musicTable[index], musicTable[i]
24
        end
25
        for i = 1, #musicTable do
26
            wait(1)
27
            script.Parent.SoundId = musicTable[i]
28
            script.Parent:Play()
29
            script.Parent.Ended:wait()
30
        end
31
    end
32
end)

For some reason, it doesn't work at all. Why?

1 answer

You'll probably need a main loop to play songs and a function to skip the current song (untested code):

local music = {
	142305080;
	671389213;
	609246843;
	1100823134;
	681266896;
	323743169;
	442656036;
	706699539;
	838691861;
};
local song = 0;
local last;
local sound = script.Parent;
local button = script.Parent.Parent;

button.InputBegan:connect(function(input)
	if(input.UserInputType == Enum.UserInputType.MouseButton1)then
		sound:Stop();
		-- stop the sound, therefore forcing *Ended* event and main loop to reset
	end
end)

while(true)do
	last = song;
	repeat
		song = math.Random(1, #music);
	until(song ~= last)
	sound.SoundId = "rbxassetid://" .. music[song];
	-- easier to add songs
	sound.Loaded:connect(sound:Play());
	-- make sure song is loaded
	sound.Ended:Wait();
	-- called when sound:Stop() is called or sound reaches end
end

1 comment

0

It doesn't work at all now, do you want me to send the model of the GUI so you can look at it?

This discussion is preserved as it was. New answers, comments, and votes are closed.