Task.delay does not work

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!
    I am trying to make a stun system.

  2. What is the issue? Include screenshots / videos if possible!
    Task.delay refuses to work and I have tried nearly everything to fix it

char:WaitForChild("RagdollTrigger").Value = true
task.delay(5, function()
	print("sd")
	char:WaitForChild("RagdollTrigger").Value = false
	print("sd")
end)
3 Likes

Are you receiving any errors in the output logs?

3 Likes

Does “SD” print after 5 seconds? If so, the problem is most likely with your ragdoll system.

1 Like

Not recieving any errors in the output logs

1 Like

The “SD” doesn’t print after 5 seconds so i dont think its the problem with the ragdoll system

1 Like

What output do you get when you do this?

local RagdollTrigger = char:WaitForChild("RagdollTrigger", 10)
print(RagdollTrigger, 'was found!')
RagdollTrigger.Value = true

task.delay(5, function()
	print("sd")
	char:WaitForChild("RagdollTrigger").Value = false
	print("sd")
end)

Edit: While testing this code, let the game run for at least 10 seconds exactly before drawing any conclusions.

2 Likes

It prints “RagdollTrigger was found!”

1 Like

Another experiment, what output do you get when you do this?

task.delay(2, function()
	print("task.delay is working!")
end)

local RagdollTrigger = char:WaitForChild("RagdollTrigger", 10)
print(RagdollTrigger, 'was found!')
RagdollTrigger.Value = true
1 Like

Only prints “RagdollTrigger was found!”

1 Like

Where is the script located? Can you still find it in the explorer after the delay time has passed? If you can, is it still enabled?

2 Likes

The script is a modulescript and it’s in ReplicatedStorage

1 Like

Your mistake is using delay over coroutines, delay has a wait in it which can take up to 25 seconds to complete. Try and use coroutines instead. Its recommended to avoid spawn and delay.

1 Like

The script that was using the modulescript had to be deleted after 2 seconds so that’s why the task.delay didnt work, thanks

2 Likes

I’ve never heard this advice before, would you mind elaborating on this rule? Why is coroutine better than task.spawn? I have previously heard that it is better to use task.spawn() over spawn(). What do you mean by this?

Thank you

This is only true for the legacy version of delay. OP was using task.delay, which does not have this problem.

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.