For this problem you should familiarize yourself with Events, like for instance the Button1Down mouse Event which fires a signal every time the mouse button is pressed down.
Your current issue is that you are binding the mouse click to your function Button1Down:Connect(function()
but then have no way to disconnect this event afterwards. What's worse, you try to bind a new function to this event, creating an ever increasing memory leak.
What you should do, is store the event you are binding as a variable - which can be done like so:
1 | local treeEvent = mouse.Button 1 Down:Connect( function () |
This is possible because the :Connect
function returns the event it creates!
So now that we have the event stored in a variable, we can call the :Disconnect()
function whenever we want to stop the game from listening for your mouse click.
This means replacing:
1 | mouse.Button 1 Up:Connect( function () end ) |
With:
Hope this helps!