Alright so i’m trying to play this audio while having this scrollingframe GUI get the value from the ScrollingFrame Label which gets named as it forms on the list.
For some reason, it won’t play the music no matter what I try.
I looked on the Developer Wiki and saw nothing on this situation and I looked into it and I see no way to fix it.
--Made By MillerrIAm
-------------------Variables------------------
Music = game:GetService("ServerStorage").MusicFolder
Event = game.ReplicatedStorage.GUIEvents.PlayMusic
------------------Main Script------------------
Event.OnServerEvent:Connect(function(plr,Play,argument)
if Play == "Yes" then
Music[""..argument].Volume = 1
Music[""..argument]:Play()
elseif Play == "No" then
Music[argument]:Stop()
end
end)
What I mean by this is I’m attempting to make it so when I click this GUI button, it fires an event that gets the value to play it while also getting the name it is to search for and play.
Like this…
When the event is fired…
It gets the name of the audio inside the argument then gets the value to play yes.
You should do some checks to see if the value argument exists, since exploiters can fire the remote event and make argument nil, causing your script to error. I also see that you’re doing “”…argument, which should just be turned into argument.
Anyway, I think the reason your music won’t play is because you’re using a colon instead of a period to set the volume.
--Made By MillerrIAm
-------------------Variables------------------
Music = game:GetService("SoundService").MusicFolder
Event = game.ReplicatedStorage.GUIEvents.PlayMusic
------------------Main Script------------------
Event.OnServerEvent:Connect(function(plr,Play,argument)
if Play == "Yes" then
Music[argument].Volume = 1
Music[argument]:Play()
elseif Play == "No" then
Music[argument]:Stop()
end
end)
I’ve rewritten your code so that it’s cleaner and hopefully works.
There are also test prints in case nothing happens.
Server:
--Made By MillerrIAm
-------------------Variables------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Music = SoundService:WaitForChild("MusicFolder")
local GUIEvents = ReplicatedStorage:WaitForChild("GUIEvents")
local MusicEvent = GUIEvents:WaitForChild("PlayMusic")
------------------Main Script------------------
MusicEvent.OnServerEvent:Connect(function(_, PlayType, Arg)
local MusicArg = Music[Arg]
if MusicArg then
if PlayType == true then
MusicArg.Volume = 1
warn("Played")
MusicArg:Play()
elseif PlayType == false then
MusicArg:Stop()
end
return
end
warn(string.format("Didn't play. MusicArg: %s Arg: %s", MusicArg, Arg))
end)
Client:
--Made By MillerrIAm
-------------------Variables------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local GUIEvents = ReplicatedStorage:WaitForChild("GUIEvents")
local MusicEvent = GUIEvents:WaitForChild("PlayMusic")
------------------Main Script------------------
script.Parent.Activated:Connect(function()
MusicEvent:FireServer(true, script.Parent.Text)
warn("Fired")
end)
Alright so, this is all working perfectly except it isn’t getting the music name hence it not playing anything. What else would you suggest I do to fix that part?
I know why.
It’s because the music folder is an instance, not a table.
You are supposed to use FindFirstChild.
Fixed code:
--Made By MillerrIAm
-------------------Variables------------------
local ReplicatedStorage = game:GetService("ReplicatedStorage")
local SoundService = game:GetService("SoundService")
local Music = SoundService:WaitForChild("MusicFolder")
local GUIEvents = ReplicatedStorage:WaitForChild("GUIEvents")
local MusicEvent = GUIEvents:WaitForChild("PlayMusic")
------------------Main Script------------------
MusicEvent.OnServerEvent:Connect(function(_, PlayType, Arg)
local MusicArg = Music:FindFirstChild(Arg)
if MusicArg then
if PlayType == true then
MusicArg.Volume = 1
warn("Played")
MusicArg:Play()
elseif PlayType == false then
MusicArg:Stop()
end
return
end
warn(string.format("Didn't play. MusicArg: %s Arg: %s", MusicArg, Arg))
end)
Well, I think it’s most likely due to the text not lining up with the song that’s supposed to be played. Therefore, there is not a song being found and it erroring.
Make sure there are no typos in either the song name or the text.
Pretty sure capitalization is very important and matching up the string, otherwise you cannot match it correctly, therefore you should work around it somehow.
Oh yeah. Now I realized that game:GetService("ServerStorage").MusicFolder. Do not play audios placed in ServerStorage, as they are unable to replicate to client. Try playing the audios from a different service. I don’t think the way I played audios was using SoundService.
Try moving MusicFolder into Workspace and playing them from there instead.