How to use repeat function without any delay

I’m trying to make multiple blood puddles at once. The only problem is to do so without crashing I need to add wait(), which delays my weapons attacks and sound effects. Is there any way to avoid this?

repeat
		local ray = workspace:Raycast(blood.Position, Vector3.new(math.random(-10, 10), math.random(-10, 10), math.random(-10, 10)), params)
		if ray and cd == false then
			--[[ if the ray works ]]--
			
			local function puddle()
				--[[ make the puddle ]]--
				
				blood.Sound:Play()
				local puddl = game.ReplicatedStorage.BloodPuddle:Clone()
				puddl.Parent = game.Workspace
				puddl.Color = blood.Color
				puddl.CFrame = CFrame.lookAt(ray.Position, ray.Position + ray.Normal) * CFrame.Angles(math.pi/2, 0, 0)
			end
			if ray.Instance.Anchored == true and ray.Instance.CanCollide == true and ray.Instance.Transparency == 0 then
				--[[ if the ray is a terrain part ]]--
				
				puddle()
			elseif ray.Instance == game.Workspace.Terrain then
				--[[ if the ray is terrain ]]--
				
				puddle()
			end
			cd = true
		end
		--[[ end ]]--
		
	until cd == true
until drops == 0

You can’t make loops with too many iterations without waiting

You can use task.wait() when you are working with waiting time shorter than 100ms because wait becomes way too imprecise at this point

Actually both task.wait and wait functions return the exact time they’ve been waiting (in seconds) so i recommend you to experiment with them in studio command bar and choose the one that will fit the best

print(wait()) - 0.04567
print(task.wait()) - 0.01314
print(task.wait(0)) - 0.00691
The values above are not constant and the time varies every call

1 Like