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)
01 | wait( 1 ) |
02 | ------------------------ |
03 | axelvl = 1 |
04 | treeMoney = 25 |
05 | resettime = 2 |
06 | ------------------------ |
07 |
08 | Tool = script.Parent |
09 | ting = 0 --this is my debounce |
10 |
11 | function hit() |
12 | print ( "hitting" ) |
13 | local anim = Instance.new( "StringValue" ) |
14 | anim.Name = "toolanim" |
15 | anim.Value = "Slash" |
So how would I make function ontouched(hitt) only fire when a mouse1down function is fired?
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:
01 | function onMouse 1 Down() |
02 | -- connect to touched event |
03 | local touchConnection = Tool.Handle.Touched:connect(onTouched) |
04 |
05 | wait(cooldown) |
06 |
07 | -- disconnect |
08 | touchConnection:Disconnect() |
09 | end |
10 | -- connect your Mouse1Down here |
NOTE: the connection to touched shouldn't happen anywhere else in the code, it should only happen in onMouse1Down
.