Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How do I activate two functions at once?

Asked by 5 years ago

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
0
Try using events. Also, why is CanOpen/CanOpen2 local variables and not functions?! VVickedDev 54 — 5y
0
The reason why I put them as local variables is because I can't activate the BindableFunction without making it a variable. rubiksmaster301 17 — 5y
0
--ONLY CHANGE IF YOU REALLY KNOW WHAT YOU'RE DOING-- Do you know what you are doing though? greatneil80 2647 — 5y

1 answer

Log in to vote
1
Answered by
hellmatic 1523 Moderation Voter
5 years ago
Edited 5 years ago

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 ```

0
THANK YOU SO MUCH I'VE BEEN TRYING TO DO THIS FOR 4 HOURS rubiksmaster301 17 — 5y
Ad

Answer this question