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

Where would i put if not debounce?

Asked by 7 years ago
wait(3)
script.Parent.Visible = true

local frame = script.Parent.Parent.Parent:WaitForChild('First')
local debounce = false
local on = false

local char = game.Players.LocalPlayer.Character.Humanoid

local cam = workspace.Camera
local int = require(game.ReplicatedStorage.Interpolate)

script.Parent.MouseButton1Click:connect(function()
if on then
 game.ReplicatedStorage.Sounds.Click:Play()
        frame:TweenPosition(UDim2.new(0, -500,0.5, -173),"In","Quad",.5,true)     --Close
        cam.CameraType = "Custom"
        wait(.4)
     on = false
else
    cam.CameraType = "Scriptable"
        int.Interpolate(cam,CFrame.new(6.75,78.302,0.25), CFrame.new(0,78,0), "InOut", "Quart", 1)  --Open
        game.ReplicatedStorage.Sounds.Click:Play()
        frame:TweenPosition(UDim2.new(0, 0,0.5, -173),"Out","Quad",.5,true)
        wait(.4)
        on = true
    end
end)

1 answer

Log in to vote
0
Answered by 7 years ago

If you want it to be unclickable while in-between opening and closing, this is the best way to do it.

Before checking if it's "on" or vice versa, it will check if debounce is false. If true, then that means it's still running code and can't be used.

Here's how it should look. Hope this helps!

wait(3)
script.Parent.Visible = true

local frame = script.Parent.Parent.Parent:WaitForChild('First')
local debounce = false
local on = false

local char = game.Players.LocalPlayer.Character.Humanoid

local cam = workspace.Camera
local int = require(game.ReplicatedStorage.Interpolate)

script.Parent.MouseButton1Click:connect(function()
if not debounce then --Debounce is off
    debounce = true --Turns debounce on
if on then
 game.ReplicatedStorage.Sounds.Click:Play()
        frame:TweenPosition(UDim2.new(0, -500,0.5, -173),"In","Quad",.5,true)     --Close
        cam.CameraType = "Custom"
        wait(.4)
     on = false
else
    cam.CameraType = "Scriptable"
        int.Interpolate(cam,CFrame.new(6.75,78.302,0.25), CFrame.new(0,78,0), "InOut", "Quart", 1)  --Open
        game.ReplicatedStorage.Sounds.Click:Play()
        frame:TweenPosition(UDim2.new(0, 0,0.5, -173),"Out","Quad",.5,true)
        wait(.4)
        on = true
    end
end --The closer for the debounce checker
debounce = false --Turn debounce back off after done running code
end)
0
Thanks! SamthekidRSsl 58 — 7y
Ad

Answer this question