Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

Spam clicking GUI button breaks the script?

Asked by 6 years ago

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

1
It's the user's fault if they spam clicked it. hiimgoodpack 2009 — 6y
0
Yes I am aware, simply resetting will fix it, just wondering if there is any way to stop it? Something that could help in the future? Other than that its no biggie CrispyBrix 113 — 6y
1
Also, use Color3.fromRGB hiimgoodpack 2009 — 6y
1
Yeah I would agree with hiimgoodpack. Learn how to use debounce as a bool variable TickTockTheory 106 — 6y

1 answer

Log in to vote
0
Answered by 6 years ago

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.

Ad

Answer this question