So this is my Code
``` local Tool = script.Parent --make sure this is a Tool object
local m = false
local plr = game.Players.LocalPlayer
Tool.Equipped:Connect(function(Mouse)
Mouse.Button1Down:Connect(function() m = true end) Mouse.Button1Up:Connect(function() m = false end)
while wait(0.01) do
while m == true do workspace.Events.AddPoints:FireServer() wait(2) end end
end) ```
The reason is your loop doesn't end when m is false What you should do is this
while m do -- code end
But what I would recommend more than a while loop for this is a repeat loop
repeat wait(.01) -- code until not m
This answer assumes you have basic knowledge of tools and their events
Hello Lodok3. :p
The problem with your tool's that each time the tools equipped, it's going to keep creating a new loop. You never set anything up to stop the one prior. Lines 27-37 yield this.
while wait(0.01) do -- Doesn't have anything set up to stop. while m == true do workspace.Events.AddPoints:FireServer() wait(2) end end
One solution can to be to instead put the second loop (while m == true do) inside the Button1Down
event. An example of this would be;
...Button1Down:Connect(function() MouseDown = true while MouseDown do -- Code end end) ...Button1Up:Connect(function() MouseDown = false end)
However, another problem arises: when the player unequips! :O Nps though, we got this covered. :p We can detect when a player unequips a tool via the Unequipped
event of a tool, and so from there, when it fires, we change MouseDown
to false.
Tool.Unequipped:Connect(function() MouseDown = false end)
If you have any questions, feel free to ask. :) I hope this helped! :D