How can i connect this script to all parts/children of a folder called “Music”?
(I wanna make it work on multiple parts with the same name)
Here is the script:
Here’s some code that should work! All it does is that it loops through the “Music” folder, then checks if it’s a part, and it has a certain name. Then, you can do whatever you want after that!
local MusicFolder = game.Workspace:WaitForChild("Music") -- change this to the location of your "Music" folder
for i, Part in pairs(MusicFolder:GetChildren()) do
if Part:IsA("Part") and Part.Name == "Part" then -- Change "Part" to the name of the parts
local music = game.Workspace.Music.MusicBlock
script.Parent.MouseButton1Click:Connect(function()
music.Sound.SoundId = "rbxassetid://17721474407"
music.Sound.Playing = true
end)
end
end
Try this instead. What I changed is that it uses every individual MusicPart, because it seemed that you were only playing it on one part:
local MusicFolder = game.Workspace:WaitForChild("Music")
for i, Part in pairs(MusicFolder:GetChildren()) do
if Part:IsA("Part") and Part.Name == "MusicBlock" then
script.Parent.MouseButton1Click:Connect(function()
Part.Sound.SoundId = "rbxassetid://17721474407"
Part.Sound.Playing = true
end)
end
end