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

Stop calling an event?

Asked by 9 years ago

Lets say I want to check for when a player presses a key with a specific tool equipped. I'd use mouse.KeyDown() in a local script in the tool. However, if I were un-equip the tool. then it would still check to see if the key is pressed. I know I could make a variable that is true when the tool is equipped and make it false when it isn't and put that within an if statement in KeyDown(), but is there a more efficient way?

2 answers

Log in to vote
2
Answered by
yoshiegg6 176
9 years ago

Wow, you're having the same problem I was having when I wanted to do this. But there's an easy solution, context action service.
It lets you press a button to activate a function but you can bind an unbind it whenever you want. So, if you don't want someone to do the function when their tool is unequipped just unbind the function when the tool is unequipped. To learn to use it just go to the tutorial above.

0
Thanks, but what if I also wanted to check if a player dies when his character is added to the game? aquathorn321 858 — 9y
1
Do you mean in the script above or do you just want to know to know. yoshiegg6 176 — 9y
Ad
Log in to vote
0
Answered by
yumtaste 476 Moderation Voter
9 years ago

I'm not entirely sure about this, but I looked on the wiki, and it said you can try RBXScriptConnection:disconnect to stop events. You can look harder than I did, but ever since the overhaul, it's been really difficult to find what you need. If that doesn't work, then I'm afraid you'll have to use the variable.

Answer this question