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

How do I activate two functions at once?

I am making an elevator with a door, and the door has two door panels. canOpen activates the first panel, and canOpen2 activates the second panel. However, when the script is ran, the first panel opens, then the second panel doesn't open until the script has finished running the canOpen script. The script shown below is inside of a bindablefunction. I wonder if there is a way around this. Thanks :)

  --ONLY CHANGE IF YOU REALLY KNOW WHAT YOU'RE DOING--

local debounce = false

local canOpen=true

local canOpen2=true

  

function script.Parent.OnInvoke()

  

    canOpen=script.Parent.Parent.Parent.Parent.Door.DoorOpener:Invoke()

    canOpen2=script.Parent.Parent.Parent.Parent.Door.DoorOpener2:Invoke()

end

3 comments

0

Try using events. Also, why is CanOpen/CanOpen2 local variables and not functions?!

0

The reason why I put them as local variables is because I can't activate the BindableFunction without making it a variable.

0

--ONLY CHANGE IF YOU REALLY KNOW WHAT YOU'RE DOING-- Do you know what you are doing though?

1 answer

✓ Accepted answer

You have to wrap one of invokes in a spawn function. It delays the opening of the panel because the first invoke yields the script (waits for it to finish).

function script.Parent.OnInvoke()
spawn(function()
	canOpen=script.Parent.Parent.Parent.Parent.Door.DoorOpener:Invoke()
end)

canOpen2=script.Parent.Parent.Parent.Parent.Door.DoorOpener2:Invoke()
end

1 comment

0

THANK YOU SO MUCH I'VE BEEN TRYING TO DO THIS FOR 4 HOURS

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