[SOLVED] Different ways to delay a script without using wait() twice

I have a normal script that uses the do function that activates an event, but I want it to wait 10 seconds before starting, but since I already have a wait() command for when the event ends, when I add a wait(10) to the beginning the script fails after second wait command but I get no warning from it.

Here is the full script.

do
	local Timer = game.ReplicatedStorage.Timer
	local inMatch = game.ReplicatedStorage.inMatch
	local Event = game.ReplicatedStorage.Event

	Event.Value = ""..script.Name
	
	Timer.Value = 10

	inMatch.Value = true
	
	script.Parent.Parent.Parent.Transparency = 1
	script.Parent.Parent.Parent.Parent.FakeButton.Transparency = 0
	
	wait(10) --Here is when the script fails but it displays no warning
	
	game.Lighting.Models.Coconut:Clone().Parent = workspace
	
	wait(20) --Here is the other wait command
	
	script.Parent.Parent.Parent.Transparency = 0
	script.Parent.Parent.Parent.Parent.FakeButton.Transparency = 1
	
	Event.Value = "None"

	inMatch.Value = false
	
	workspace.Coconut:Destroy()
	debounce = false
	
		print("Event Done!")
end

I’ve tried using countdown loops, pairs, but nothing seems to work for me, would there be any way to delay the script by 10 seconds without the script failing?

Plus this script is activated by its parent, using:

nextPick.Disabled = false

If that at all effects the script too.

I’ve also looked at other posts for help but no luck, so if there is one for it too let me know.

If you could help that would be great, thank you!

coroutine.yield() might be useful to you here if I am understanding correctly

How should I implement it into that script?

Try to test on where the exact location it doesn’t work by adding print statements after every line (or every significant line). I can’t see anything that would make wait(10) not work. It could be that another script/some part of your code is messing with the script.

2 Likes

What exactly are you trying to do?

It stops printing at line 21, right before the second wait command, line 22:

wait(10) -- line 20, the first wait command
print("Test") -- line 21, a test print to see when it stops
wait(30) --line 22, where it stops working

Right before line 21 is the first wait command, so I’m not really sure.

Can you try printing the wait call? Anyways, I recommend you to use the new task library, since wait is now deprecated will be declared deprecated.

Nope, I even waited over 60 seconds and still nothing happened after line 21.

I will try the task library and let you know what happens

Thank you so much!

I swapped both wait commands with task.wait and it worked!

wait isn’t deprecated yet as the task library new, but plans to deprecate it in the future are probable.

1 Like