Hello fellow reader, I simply have a question about functions. I am having this issue where if I have a function inside of a function, I get this type of loop where if I run function-MouseEnter around 5 times. It of course prints("Hi") 5x times. But if I then run function-MouseButton1Down 1x time. Then function-MouseButton1Down gets fired 5 times. Even though I ran it only 1 time. And if I run function 2 again it runs 5 times instead of only one.
script.Parent.MouseEnter:Connect(function() print("Hi") connection = Items.Sword.MouseButton1Down:Connect(function() print("Hi2") end) end)
Could someone explain how to end the loop? I am really confused about functions so please tell me if there was something you didn't understand. It's kinda hard to explain this certain problem but its crucial for me to fix. Any help would be thanked
Every time the MouseEnter function activates, it creates a new instance of the MouseButton1Down function. In this case, you ran the MouseEnter function 5 times. That made the script create 5 instances of the MouseButton1Down function. When you then try to trigger the second function, all five instances activates at ones and thus "Hi2" is printed five times.
found a solution. I was such an idiot. Instead of having the function inside, I put it outside