Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

delay requires 2 arguments?

Hi, my script randomly stopped working. It's a sound looper that seamlessly plays audio.

Error here is delay requires 2 arguments @ line 24

any ideas what's going on here?

--getLength
for i,v in pairs (script.Parent:GetChildren()) do
	if v:isA("Sound") then
		soundObj = v
		print("got sound ... " .. soundObj.Name)
	end
end

soundLength = soundObj.TimeLength
print("length = " .. soundLength)

function countDown(sound)
	sound:remove()
end

wait() 

while true do
	local newSound = soundObj:clone()
	newSound.Parent = script.Parent
	newSound:play()
	print("played new sound .. " ..newSound.Name)
	print("length = " .. soundLength)
	delay(soundLength, countDown(newSound)) -- line in question
	print("delay fired")
	wait(soundLength-1)
end

1 answer

✓ Accepted answer

The problem is that you are calling countDown rather than passing it. This means that you instead pass the return value of countDown which is nil. You need to wrap the call in an anonymous function, like this:

delay(soundLength, function() countDown(newSound) end)

1 comment

0

You just saved me from a very very bad time. Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.