Task.wait() not running any code after

I have checked if it runs before or after, and it only runs before. It should wait one second, and then run the next code. But it doesn’t AHSDfvgt3eauhe

I can fix this with other methods but I just want to know why the code isn’t running.

Code:

task.wait(1) workspace.Stuff.Cooldowns.Change:Fire(Deb:FindFirstChild(script.Parent.Parent.Battler.Value), false)

For example, it prints before the task.wait, but not after.

Are you wrapping this code in something else? Like a method or a function? I believe there are methods/functions where if you include a delay it would break it

Hold on here’s the entire script

task.wait(1)

Deb = workspace.Stuff.Cooldowns
Battler = script.Parent.Parent.Battler
Plr = script.Parent.Parent.Parent.Parent.Parent

script.Parent.MouseButton1Click:Connect(function()
if Deb:FindFirstChild(script.Parent.Parent.Battler.Value).Value == false then
workspace.Stuff.Cooldowns.Change:Fire(Deb:FindFirstChild(script.Parent.Parent.Battler.Value), true)

  local Team = nil
  local Waittime = Deb:FindFirstChild(script.Parent.Parent.Battler.Value).Length.Value

  if Plr.TeamColor == BrickColor.new("Really red") then
  	Team = "Red"
  elseif Plr.TeamColor == BrickColor.new("Bright blue") then
  	Team = "Blue"
  else
  	error("You have to be on blue or red to use this battler.")
  end
  
  local BattlerName = (Team..""..Battler.Value)
  task.wait()
  local Morph = game.ServerStorage.Morphs:FindFirstChild(Team):FindFirstChild(Team..""..Battler.Value)

  task.spawn(function()
  	workspace.Stuff.MorphHandler.Event:Fire(Plr, Morph, Battler.Value, Team)
  end)
  
  task.wait(1)
  workspace.Stuff.Cooldowns.Change:Fire(Deb:FindFirstChild(script.Parent.Parent.Battler.Value), false)

end
end)

It is a serverscript located in PlayerGui. It sends a notice to a BindableEvent (Change) in workspace. The event runs the first time it is called upon before task.wait, but not the second.

To be honest, I’m not sure what’s going on here maybe someone else can see it but I do have an alternative solution (Doesnt relate to the issue but solves it).

try this:

task.delay(1, function()
			workspace.Stuff.Cooldowns.Change:Fire(Deb:FindFirstChild(script.Parent.Parent.Battler.Value), false)
		end)

Also, why are you wrapping the code above the task.wait(1) in a different thread? All the code does is fire an event so you don’t really need it.

Nope, doesn’t work.

I have another idea for what I could do, I’m just really curious why it’s not working.

I wrapped the code above in a different thread just in case they were interfering, idk why I kept it but yeah.

Weird… Remove the wait and see if the code below runs

Without the wait, it works completely fine.

I’ll just throw out random ideas but maybe try the wait function?

Nope.

Found a solution though.
I put the task.wait inside the Change event script.
It works.
Not really sure what Roblox is doing…

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