I am trying to do GetChildren() on a folder, but it comes back as nothing. The folder constantly has Sounds going in and out, so how would I go about trying to make it find the Child every time a new Sound is added into the folder? I already tried combining the scripts, but it was a mess.
Here is the script that works with the Folder, it puts the cloned Sound into the Current Song Folder:
local starterGui = game:GetService("StarterGui") local shuffleBtn = script.Parent local musicFolder = starterGui.MusicGui:WaitForChild("MusicFolder") local songs = musicFolder:GetChildren() local currentSongFolder = starterGui.MusicGui:WaitForChild("CurrentSongFolder") shuffleBtn.MouseButton1Click:Connect(function() currentSongFolder:ClearAllChildren() wait(0.5) local chosenSong = songs[math.random(1, #songs)] local songClone = chosenSong:Clone() songClone.Parent = songClone songClone:Play() end)
And here is the code where I am trying to make it so when a new Sound is added, it will look to see if a Child was Added to the Current Song folder:
local starterGui = game:GetService("StarterGui") local sliderBG = script.Parent local slider = sliderBG:WaitForChild("Slider") local currentSongFolder = starterGui.MusicGui:WaitForChild("CurrentSongFolder") local currentSong = currentSongFolder:GetChildren() local mouse = game.Players.LocalPlayer:GetMouse() local snapAmount = 1 local pixelsFromEdge = 1 local movingSlider = false slider.MouseButton1Down:Connect(function() movingSlider = true end) slider.MouseButton1Up:Connect(function() movingSlider = false end) mouse.Button1Up:Connect(function() movingSlider = false end) mouse.Move:Connect(function() if movingSlider then local xOffset = math.floor((mouse.X - sliderBG.AbsolutePosition.X) / snapAmount + 0.5) * snapAmount local xOffsetClamped = math.clamp(xOffset, pixelsFromEdge, sliderBG.AbsoluteSize.X - pixelsFromEdge) local sliderPosNew = UDim2.new(0, xOffsetClamped, slider.Position.Y) slider.Position = sliderPosNew local roundedAbsSize = math.floor(sliderBG.AbsoluteSize.X / snapAmount + 0.5) * snapAmount local roundedOffsetClamped = math.floor(xOffsetClamped / snapAmount + 0.5) * snapAmount local sliderValue = roundedOffsetClamped / roundedAbsSize currentSong.Volume = sliderValue end end)
You can detect if a child is added with this function
musicFolder.ChildAdded:Connect(function(child) --You can use the "child" as you want end)
Also:
songClone.Parent = songClone --In this line you're parenting the songClone to itself
Edit: To use it outside of the function, you can create and empty variable, then just assign the child to it:
local song --you can call it anything you want, but leave it empty musicFolder.ChildAdded:Connect(function(child) song = child --now you can use it anywhere end)