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

Drawer Script runs more than it should, Help?

Asked by 3 years ago
Edited 3 years ago

When you hover your cursor over the drawer it has a little interact GUI that shows up and when you click it slide opens and close.

I have this one problem where if you spam click the drawer it goes more further than it should (I think it has something to do with the script doing running more than it should).

I tried changing the clickdetector activation distance to 0 while it runs then changing it back. Then I added a wait timer after changing it to 0 to wait for the server to keep up.

Script:

local Drawer = script.Parent
local clickDetector = Drawer.ClickDetector
local Gui = Drawer.Parent.Gui2.BillboardGui
local Opened = false

clickDetector.MouseClick:Connect(function()
    clickDetector.MaxActivationDistance = 0
    wait(0.1)
    if Opened == false then
        Gui.Enabled = false
        for i = 1,25 do
            Drawer.CFrame = Drawer.CFrame * CFrame.new(0,0,-0.05)
            wait()
        end
        Opened = true
    end
    clickDetector.MaxActivationDistance = 10
end)

clickDetector.MouseClick:Connect(function()
    clickDetector.MaxActivationDistance = 0
    wait(0.1)
    if Opened == true then
        Gui.Enabled = false
        for i = 1,25 do
            Drawer.CFrame = Drawer.CFrame * CFrame.new(0,0,0.05)
            wait()
        end
        Gui.Enabled = true
        Opened = false
    end
    clickDetector.MaxActivationDistance = 10
end)

1 answer

Log in to vote
0
Answered by 3 years ago
Edited 3 years ago

So you are telling me, you have a debounce but you don't use it...

Ok, so I'm assuming u copied the code or something, since your not using the debounce what so ever, but I GOT U FAm.

A debounce is just a name for a variable that stops code from running multiple times; you have one, your just not using it? (FYI: A debounce can have any name, because its just a variable)

local Drawer = script.Parent
local clickDetector = Drawer.ClickDetector
local Gui = Drawer.Parent.Gui2.BillboardGui
local Opened = false
local debounce = false

clickDetector.MouseClick:Connect(function()
        clickDetector.MaxActivationDistance = 0
        wait(0.1)
        if Opened == false then
        if  debounce  == false then
            debounce = true
                Gui.Enabled = false
                for i = 1,25 do
                    Drawer.CFrame = Drawer.CFrame * CFrame.new(0,0,-0.05)
                    wait()
                end
                Opened = true
                clickDetector.MaxActivationDistance = 10
        end
           else --Open == true
            Gui.Enabled = false
            for i = 1,25 do
                Drawer.CFrame = Drawer.CFrame * CFrame.new(0,0,0.05)
                wait()
            end
            Gui.Enabled = true
            Opened = false
            clickDetector.MaxActivationDistance = 10
        wait(0.2)
        debounce = false
    end
end)
0
ty fam (and no i wrote the script from scratch) omeed2006 7 — 3y
Ad

Answer this question