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

Extreme lag from MouseButton1Down:Connect ?

Asked by 6 years ago

If I click in the boundary, everything is fine. If I click outside the boundary it returns Out of bounds (x2), if I click outside again it returns Out of bounds (x8) and keeps increasing until it reaches something crazy like (x8432), when the game lags out and crashes.

function Place()
    if Placing == true and Debounce == true then
        Mouse.Button1Down:connect(function()
            Debounce = false
            if InBoundary == true and IsColliding == false and Placing == true then
                -- irrelevant code
                if Mouse.Target == nil then
                    return
                end
                if Placing == true then
                    Mouse.TargetFilter = nil
                    Placing = false
                elseif not Placing then
                    return
                end
                Placing = false
            elseif InBoundary == false then
                print("Out of bounds.")
                Blink()
                Place()
            elseif IsColliding == true then
                print("Object already here.")
                Blink()
                Place()
            end
            Debounce = true
        end)
    end
end

How can I fix this? I tried adding a Debounce.

0
Is this the whole script rilgundam 65 — 6y
0
you need to disconnect the function abnotaddable 920 — 6y

1 answer

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

I think you need to disconnect it

function Place()
    if Placing == true and Debounce == true then
    local bt;
        bt = Mouse.Button1Down:Connect(function() --USE "Connect" !!!!! "connect" is deprecated!!!!!!!!
            Debounce = false
            if InBoundary == true and IsColliding == false and Placing == true then
                -- irrelevant code
                if Mouse.Target == nil then
                    return
                end
                if Placing == true then
                    Mouse.TargetFilter = nil
                    Placing = false
                elseif not Placing then
                    return
                end
                Placing = false
            elseif InBoundary == false then
                print("Out of bounds.")
                Blink()
                Place()
            elseif IsColliding == true then
                print("Object already here.")
                Blink()
                Place()
            end
            Debounce = true
    bt:Disconnect()
        end)
    end
end
0
Read my bio. hiimgoodpack 2009 — 6y
0
i litterally just copied and pasted the script. and then added a few parts in, I know how to indent bro abnotaddable 920 — 6y
0
That doesn't work, once it's disconnected the function doesn't connect again. shadow7692 69 — 6y
Ad

Answer this question