How would I index sound properties

I made a radio but the issue is it only check if one sound is playing. I think anyways that’s what’s happening. I only want it to play one audio at a time but it keeps trying to play multiple or restarts the one already playing. Someone said I should index IsPlaying properties but I have no idea how to do that and looking at other dev forums I cant make sense of it.
code


local joey = true


while joey do
	
	for i,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Sound") then
			local joe = math.random(1, 3)
			print(joe)
			if v.Playing == false then
				if joe == 1 then
					script.Parent.HardRockMadness:Play()
					print("playing rock madness")
				end
				if joe == 2 then
					script.Parent["Fallschirmjäger"]:Play()
					print("Playing fallschrimjager")
				end
				if joe == 3 then
					script.Parent.RockStyle:Play()
					print("Playing RockStyle")
				end
				wait(10)
			end
		end
	end
end

In the future it is better to just reply to your original post instead of generating a new one for the same issue.

In this case, you should iterate through the sounds you want to index using :GetChildren() or :GetDescendants().

Use this code before you play sounds.

for _,v in pairs(script.Parent:GetChildren()) do
    if v:IsA(“Sound”) then
        v:Stop()
    end
end

The thing is im not trying to stop playing sounds im trying to detect if all the sounds arent playing.

function checkIfPlaying(model)
    for _,v in pairs(model:GetChildren()) do
        if v:IsA(“Sound”) and v.IsPlaying then
            return true
        end
    end
    return false
end

local soundsArePlaying = checkIfPlaying(script.Parent)
1 Like

so I did this and nothing changed

function checkIfPlaying()
	for _,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Sound") and v.IsPlaying then
			return true
		end
	end
	return false
end

local soundsArePlaying = checkIfPlaying(script.Parent)





local joey = true


while joey do
	
	checkIfPlaying()
	if soundsArePlaying == false then
		local joe = math.random(1, 3)
		print(joe)

		if joe == 1 then
			script.Parent.HardRockMadness:Play()
			print("playing rock madness")
		end
		if joe == 2 then
			script.Parent["Fallschirmjäger"]:Play()
			print("Playing fallschrimjager")
		end
		if joe == 3 then
			script.Parent.RockStyle:Play()
			print("Playing RockStyle")
		end
		wait(10)
	end		
end

function checkIfPlaying()
	for _,v in pairs(script.Parent:GetChildren()) do
		if v:IsA("Sound") and v.IsPlaying then
			return true
		end
	end
	return false
end






local joey = true


while wait() do
	
	local soundsArePlaying = checkIfPlaying(script.Parent)
	if soundsArePlaying == false then
		local joe = math.random(1, 3)
		print(joe)

		if joe == 1 then
			script.Parent.HardRockMadness:Play()
			print("playing rock madness")
		end
		if joe == 2 then
			script.Parent["Fallschirmjäger"]:Play()
			print("Playing fallschrimjager")
		end
		if joe == 3 then
			script.Parent.RockStyle:Play()
			print("Playing RockStyle")
		end
		wait(10)
	end		
end
1 Like