Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

Extreme lag from MouseButton1Down:Connect ?

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.

2 comments

0

Is this the whole script

0

you need to disconnect the function

1 answer

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

3 comments

0

Read my bio.

0

i litterally just copied and pasted the script. and then added a few parts in, I know how to indent bro

0

That doesn't work, once it's disconnected the function doesn't connect again.

This discussion is preserved as it was. New answers, comments, and votes are closed.