Let's get your errors:
#1. Using a numeric loop instead of a generic loop
Using generic loops make you get all the contents of a table:
local Audios = game.Workspace.DJBoardPRO:GetChildren()
script.Parent.MouseButton1Down:connect(function()
for i,v in pairs(Audios) do
if v.Name == "Sound" then
v.Volume = "1"
wait(0.05)
v.Volume = "0.8"
wait(0.05)
v.Volume = "0.6"
wait(0.05)
v.Volume = "0.4"
wait(0.05)
v.Volume = "0.2"
wait(0.05)
v:Stop()
wait(.1)
v:Destroy()
end
end
end)
#2. Strings for float value?
You're setting a float value with a string one, so, let's change it - probably the main cause of your error
local Audios = game.Workspace.DJBoardPRO:GetChildren()
script.Parent.MouseButton1Down:connect(function()
for i,v in pairs(Audios) do
if v.Name == "Sound" then
v.Volume = 1
wait(0.05)
v.Volume = 0.8
wait(0.05)
v.Volume = 0.6
wait(0.05)
v.Volume = 0.4
wait(0.05)
v.Volume = 0.2
wait(0.05)
v:Stop()
wait(.1)
v:Destroy()
end
end
end)
#3. Using a second for loop
Using another for loop cleans up your script and make it look more professional.
local Audios = game.Workspace.DJBoardPRO:GetChildren()
script.Parent.MouseButton1Down:connect(function()
for i,v in pairs(Audios) do
if v.Name == "Sound" then
for i = 1,0,-0.2 do
v.Volume = i
wait()
end
v:Stop()
wait(.1)
v:Destroy()
end
end
end)
#4. Coroutines
If you want to make the sounds fade out at the same time, you may use a coroutine, else, ignore this step:
local Audios = game.Workspace.DJBoardPRO:GetChildren()
script.Parent.MouseButton1Down:connect(function()
for i,v in pairs(Audios) do
if v.Name == "Sound" then
fadeOut = coroutine.create(function()
for i = 1,0,-0.2 do
v.Volume = i
wait()
end
v:Stop()
wait(.1)
v:Destroy()
end)
coroutine.resume(fadeOut)
end
end
end)
1 comment
Thanks dude, this helps a lot, saving for refrence