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

How to call 2 different functions under 1 event ?

Asked by 4 years ago
Edited 4 years ago

I have been scripting for 2 weeks now, my question is how can i possibly call 2 functions under 1 event, for example if I am trying to create a animated button door how am i gonna make the functions not run at the same time ?

Thanks

2 answers

Log in to vote
0
Answered by 4 years ago
Edited 4 years ago

You just need to use if and elseif statements:

local Opened = false
script.Parent.MouseClick:Connect(function() --Script is located in a "ClickDetector"
    if Opened == false then --Checks to see if it's false
        Opened = true --sets to true
        print("Door is open")
    elseif Opened == true then --If the value is not false it immediately runs this part
        Opened = false
        print("Door is closed")
    end
end)

More info about if statements/Conditional statements: https://developer.roblox.com/en-us/articles/Conditional-Statements-in-Lua

0
thank you so much, now my night vision button script is completed, your answer will be have a huge impact over my future goals InfiniteBlackFlame 2 — 4y
Ad
Log in to vote
0
Answered by 4 years ago
function a()
    print("bruh")
end

function b()
    print("moment")
end

event:Connect(function()
    a()
    b()
end)

>>>bruh
>>>moment

do you mean something like this?

0
no i mean how do i make the door open when i press the button and how do i make it close when i press the button again InfiniteBlackFlame 2 — 4y

Answer this question