Sounds not emitting properly from clones?

This issue stems from a previous issue I had yesterday. I’m very new to scripting, and I have a script that creates clones in a radius. There is two issues I have.

I can’t figure out why the pitch of the sounds is not randomized according to the script even though I have a variable which is supposed to do just that.

The sound doesn’t even emit half the time either.

The script is:

local function yes()
	Pitch = math.random(.7,1.3)
	num1 = math.random(-50,50)
	num2 = math.random(-50,50)
	num3 = math.random(-50,50)
	local Clone = workspace.Part:Clone()
	task.spawn(function()
		task.wait(2)
		Clone:Destroy()
	end)
	Clone.Position = Vector3.new(num1,num2,num3)
	Clone.Parent = workspace
	task.wait(0.1)
	Clone.Sound.PlaybackSpeed = Pitch
	Clone.Sound.Playing = true
	Clone.ParticleEmitter:Emit(20)
	
	
end

while true do
	task.wait(0.5)
	yes()
end

Another issue I might want to tackle is that I can’t get the clones to spawn faster than a certain rate. (Around a 10th of a second)

The issue here is math.random(.7,1.3) as random only works with integers, so speed is sometimes 1 (plays) and sometimes 0 (doesnt play)

To fix this you can just do math.random(70,130)/10 ;D

Thank you, this worked to fix the pitches!

I’ve managed to fix my issue by just putting the stuff that required a wait function inside of a “task.spawn.” I will still definitely take a look at this video though!

Alsoo use task.delay() for delayed threads!

Example

Instead of

task.spawn(function()
	task.wait(2)
	Clone:Destroy()
end)

Do

task.delay(2,function()
    Clone:Destroy()
end)