Spam clicking GUI button breaks the script?
Its a button that opens your stats. you click it and it'll do a little effect and show you them, and it undo's it when you click it again. All works well but a friend pointed out that if you spam click the button fast enough you can glitch out the part that changes your FOV and it breaks.
Error:
18:52:10.163 - FieldOfView set out of range, should be between 1.000000 and 120.000000, setting to 120.000000 (x3962)
And that Large number at the end just increases very fast.
Lines altering FOV are 16 and 27.
Here is the script:
01 | local but = script.Parent |
04 | but.MouseButton 1 Click:connect( function () |
05 | but.TextColor 3 = Color 3. new( 0 , 0 , 0 ) |
07 | but.TextColor 3 = Color 3. new( 255 , 255 , 255 ) |
10 | but.Parent.Back.Visible = true |
13 | game.Lighting.Blur.Size = game.Lighting.Blur.Size + 1 |
14 | game.Lighting.CC.Brightness = game.Lighting.CC.Brightness + 0.01 |
15 | game.Lighting.CC.Contrast = game.Lighting.CC.Contrast + 0.1 |
16 | workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + 0.8 |
18 | until game.Lighting.Blur.Size = = 19 |
20 | elseif open = = true then |
21 | but.Parent.Back.Visible = false |
24 | game.Lighting.Blur.Size = game.Lighting.Blur.Size - 1 |
25 | game.Lighting.CC.Brightness = game.Lighting.CC.Brightness - 0.01 |
26 | game.Lighting.CC.Contrast = game.Lighting.CC.Contrast - 0.1 |
27 | workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView - 0.8 |
29 | until game.Lighting.Blur.Size = = 0 |
i'm not quite sure why spam clicking causes this, is there a way to stop this? Any help is appreciated