Hey Developers!
So I am making a music player for my airline, it chooses a random song, and then plays it, they are all in my music folder. It works fine, but I might need to either skip a song, or stop it, and then be able to resume the song, so I have made several commands, /Stop which stops the song, and doesn’t resume it until someone types /Resume also, I made it so that the player must be a certain role in my group, and I made a /Skip command. However, even thought I made a function for these, How can I make them actually work?
Here is my script:
--Music Player
local Stopped = false
local MusicFolder = game.Workspace.Music
local Status = game.ReplicatedStorage:WaitForChild('Status')
function PlayRandomSong()
local ChosenSong = MusicFolder:GetChildren()[math.random(1, #MusicFolder:GetChildren())]
ChosenSong.Playing = true
Status.Value = ChosenSong.Name
wait(ChosenSong.TimeLength)
end
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
if msg == '/Stop' or '/stop' and Player:GetRankInGroup(5875291) >= 9 then
--This is where I will need to stop the music
elseif msg == '/skip' or '/Skip' and Player:GetRankInGroup(5875291) >= 9 then
--This is where I will need to skip the current music
elseif msg == '/Resume' or '/resume' and Player:GetRankInGroup(5875291) >= 9 then
if Stopped == true then
--Resume the music if it has been stopped
end
end
end)
end)
while true do
wait(1)
PlayRandomSong()
end
So basically, I modified m script so it looks like this:
--Music Player
local Stopped = false
local MusicFolder = game.Workspace.Music
local Status = game.ReplicatedStorage:WaitForChild('Status')
function PlayRandomSong()
local ChosenSong = MusicFolder:GetChildren()[math.random(1, #MusicFolder:GetChildren())]
ChosenSong.Playing = true
Status.Value = ChosenSong.Name
wait(ChosenSong.TimeLength)
game.Players.PlayerAdded:Connect(function(Player)
Player.Chatted:Connect(function(msg)
if msg == '/Stop' or '/stop' and Player:GetRankInGroup(5875291) >= 9 then
--This is where I will need to stop the music
ChosenSong:Pause()
elseif msg == '/skip' or '/Skip' and Player:GetRankInGroup(5875291) >= 9 then
--This is where I will need to skip the current music
ChosenSong:Stop()
PlayRandomSong()
elseif msg == '/Resume' or '/resume' and Player:GetRankInGroup(5875291) >= 9 then
if Stopped == true then
--Resume the music if it has been stopped
ChosenSong:Resume()
end
end
end)
end)
end
while true do
wait(1)
PlayRandomSong()
end
Do not mix the chatted with the PlayRandomSong, make them separate.
You need to go to the sound object in Workspace or wherever you placed it, not the table value.