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

how to disable a function with another function? easy

Asked by
14dark14 167
4 years ago
Edited 4 years ago

Ok, so I have 2 functions in this script. When you equip a tool it will wait 1 second and then change the value of a variable and the other functions wait till the value of the variable is changed and it runs. It works now, but It's not professional and very good in my opinion

Any other way of doing this?

Local script Inside tool

local part = game.Workspace.Part
local tool = script.Parent
tool.Equipped:Connect(function()
    wait(1)
    b = 1
    print("ready")
end)
function lol()
    if b == 1 then
    print("gone")
    script.Parent:Destroy()
    end
end
part.TouchEnded:Connect(lol)

I just want 1 second delay for the "lol" function

**Please read what I said before answering **

2 answers

Log in to vote
1
Answered by
JesseSong 3916 Moderation Voter Community Moderator
4 years ago
local part = game.Workspace.Part
local tool = script.Parent
tool.Equipped:Connect(function()
    wait(1)
    b = 1
    print("ready")
end)

local function lol()
    print("HI")
end

delay(.5, lol) 
    if b == 1 then
    print("gone")
    script.Parent:Destroy()
    end
end
part.TouchEnded:Connect(lol)
0
Added an extra end. Remove that end on line 18. This code that I gave to you was untested, so it might error out. JesseSong 3916 — 2y
Ad
Log in to vote
1
Answered by
AspectW 431 Moderation Voter
4 years ago

Use delay.

Example:

local function lol()
    print("HI")
end

delay(1, lol) -- call on function lol() in 1 second.
0
how do you use it in this situation? part.TouchEnded:Connect(lol) 14dark14 167 — 4y

Answer this question