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

How would I make a function fire after another function has been fired?

Asked by 6 years ago

I need to know this because I'm trying to make an ax that works by mouse1down and onTouched but I don't know how to do that. Heres the current script (from toolbox)

01wait(1)
02------------------------
03axelvl = 1
04treeMoney = 25
05resettime = 2
06------------------------
07 
08Tool = script.Parent
09ting = 0 --this is my debounce
10 
11function hit()
12    print("hitting")
13    local anim = Instance.new("StringValue")
14    anim.Name = "toolanim"
15    anim.Value = "Slash"
View all 53 lines...

So how would I make function ontouched(hitt) only fire when a mouse1down function is fired?

1 answer

Log in to vote
1
Answered by 6 years ago

What you could do is only listen to the event in the Mouse1Down function, and disconnect it after some cooldown. You could do this by creating a connection through :Connect(), and using :Disconnect() on the connection after.

Like so:

01function onMouse1Down()
02    -- connect to touched event
03    local touchConnection = Tool.Handle.Touched:connect(onTouched)
04 
05    wait(cooldown)
06 
07    -- disconnect
08    touchConnection:Disconnect()
09end
10-- connect your Mouse1Down here

NOTE: the connection to touched shouldn't happen anywhere else in the code, it should only happen in onMouse1Down.

Ad

Answer this question