Got it after tossing in a bunch of wait()s (and removing the else's to remove complications) now i gotta just figure out which wait() did it and why this part was causing issues. Thanks!!!
mouse.Button1Down:Connect(function() ***** ButtonDown = true ***** while ButtonDown do if ready == true then local p = mouse.Target if p.Locked == false and (p.Position - Tool.Parent.Head.Position).Magnitude < 15 then ready = false local Data = {Part = mouse.Target, Color = ColorSelection} ServerControls:InvokeServer("PaintPart", Data) wait(1) ready = true else end else end end end) mouse.Button1Up:Connect(function() ButtonDown = false end)
Basically this is part of a painting script. It was going fine until I tried to add in a cooldown. The cooldown works when the player continues to hold down the mouse, but if they attempt to double click, theres an error from the starred line.
I'm just a bit confused where this is going wrong. Does anyone have advise?
Thanks!
I see many scenarios where your game would crash due to an infinite loop (loop keeps going without a wait). You have to be careful with all your conditions inside your loop.
simple solution is to put a wait
before the loop ends not in a condition statement
mouse.Button1Down:Connect(function() ***** ButtonDown = true ***** while ButtonDown do if ready == true then local p = mouse.Target if p.Locked == false and (p.Position - Tool.Parent.Head.Position).Magnitude < 15 then ready = false local Data = {Part = mouse.Target, Color = ColorSelection} ServerControls:InvokeServer("PaintPart", Data) ready = true else end else end wait(1) end end) mouse.Button1Up:Connect(function() ButtonDown = false end)
Take a look at the first condition of the loop:
mouse.Button1Down:Connect(function() ButtonDown = true while ButtonDown do if ready == true then ... wait(1) else end end end) mouse.Button1Up:Connect(function() ButtonDown = false end)
what if ready isn't true? the loop will still run infinitely without a wait causing it to crash. same goes for all the if statements under it, if it doesnt meet the condition the loop would just run infinitely and cause a crash