How to do two functions at the same time?

I want to do two functions at the same time

I couldn’t find a solution because I’m not very experienced at scripting.

local function test()
  print("test function started")
  wait(1)
  print("test function ended")
end

script.Parent.Equipped:Connect(function()
  print("player grabbed a tool")
  test() --There is a 1 second wait here but I don't want it to happen
  workspace.Part.BrickColor = BrickColor.Black()--This event should happen instantly
end)

Even if it is an alternative solution, I would appreciate help. Thanks in advance.

Coroutine it

local function test()
  print("test function started")
  wait(1)
  print("test function ended")
end

script.Parent.Equipped:Connect(function()
  print("player grabbed a tool")
  coroutine.wrap(test)() -- The () at the end is required for the coroutined function to run
  workspace.Part.BrickColor = BrickColor.Black()--This event should happen instantly
end)

it’ll run that function separately from the other stuff

2 Likes

Thank you so much! :slight_smile:

1 Like

Anytime! If you have anymore isuses don’t be afraid to make another post!

Oh and here’s a coroutine guide to help you understand more

1 Like