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:
local but = script.Parent local open = false but.MouseButton1Click:connect(function() but.TextColor3 = Color3.new(0, 0, 0) wait(0.1) but.TextColor3 = Color3.new(255, 255, 255) but.Click:Play() if open == false then but.Parent.Back.Visible = true but.Woosh:Play() repeat game.Lighting.Blur.Size = game.Lighting.Blur.Size + 1 game.Lighting.CC.Brightness = game.Lighting.CC.Brightness + 0.01 game.Lighting.CC.Contrast = game.Lighting.CC.Contrast + 0.1 workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + 0.8 wait() until game.Lighting.Blur.Size == 19 open = true elseif open == true then but.Parent.Back.Visible = false but.Woosh:Play() repeat game.Lighting.Blur.Size = game.Lighting.Blur.Size - 1 game.Lighting.CC.Brightness = game.Lighting.CC.Brightness - 0.01 game.Lighting.CC.Contrast = game.Lighting.CC.Contrast - 0.1 workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView - 0.8 wait() until game.Lighting.Blur.Size == 0 open = false end end)
i'm not quite sure why spam clicking causes this, is there a way to stop this? Any help is appreciated
You can use a wait() right after the click function so if they open it, it will take a little bit for it to open. that will hopefully stop the spam clicking.
local but = script.Parent local open = false but.MouseButton1Click:connect(function() wait(2) but.TextColor3 = Color3.new(0, 0, 0) wait(0.1) but.TextColor3 = Color3.new(255, 255, 255) but.Click:Play() if open == false then but.Parent.Back.Visible = true but.Woosh:Play() repeat game.Lighting.Blur.Size = game.Lighting.Blur.Size + 1 game.Lighting.CC.Brightness = game.Lighting.CC.Brightness + 0.01 game.Lighting.CC.Contrast = game.Lighting.CC.Contrast + 0.1 workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView + 0.8 wait() until game.Lighting.Blur.Size == 19 open = true elseif open == true then but.Parent.Back.Visible = false but.Woosh:Play() repeat game.Lighting.Blur.Size = game.Lighting.Blur.Size - 1 game.Lighting.CC.Brightness = game.Lighting.CC.Brightness - 0.01 game.Lighting.CC.Contrast = game.Lighting.CC.Contrast - 0.1 workspace.CurrentCamera.FieldOfView = workspace.CurrentCamera.FieldOfView - 0.8 wait() until game.Lighting.Blur.Size == 0 open = false end end)
Hopefully this helps. (You can try moving the wait(2) around to where you think it will work better.