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

GUIs keep flashing and selection box sticking? (Coroutine based, difficult, unsolved)

Alright, so, you might have seen my previous question, but I've been working on it heavily and it has now evolved. However, this time, the GUIs are flashing, and if I move my mouse too fast, the selection boxes stick, and will randomly shut off if I touch something else (meaning it won't always shut off when supposed to)

I've found that whenever I let the game sit for about 3 seconds, then try to mouse over the blocks to show the selection boxes, they never stick, no matter how fast I move the mouse. If the selection boxes aren't sticking, then the GUIs don't flash if the mouse is moving fast. If the mouse is moving slowly, they will flash.

The code is now much more advanced and may be more difficult to help solve. Here's the code --

local mouse = game.Players.LocalPlayer:GetMouse()
local debounce = false
local debounce1 = false
local debounce2 = false
local debounce3 = false
local maintarg 
local selection
local moving = false
local debounceI = false

-- The next 3 functions are called upon in the second to last function, and don't need to be read right away.

function Empty(target)
    if not debounce1 then
		debounce1 = true
		local EmptyC = coroutine.create(function()
			local selectionBox = Instance.new("SelectionBox", target) 
			selectionBox.Adornee = target 
			selectionBox.Color = BrickColor.new("Really red")
			repeat wait() until maintarg ~= target and moving == true
			selectionBox:Destroy()
		end)
		coroutine.resume(EmptyC)
		debounce1 = false
	end
end

function Storage(target)
    if not debounce2 then
		debounce2 = true
		local StorageC = coroutine.create(function()
			target:FindFirstChild("InfoStorage", true).Enabled = true
			local selectionBox = Instance.new("SelectionBox",target) 
			selectionBox.Adornee = target 
			selectionBox.Color = BrickColor.new("Bright orange")
			repeat wait() until maintarg ~= target and moving == true
			target:FindFirstChild("InfoStorage", true).Enabled = false
			selectionBox:Destroy()
		end)
		coroutine.resume(StorageC)
		debounce2 = false
	end
end

function Housing(target)
    if not debounce3 then
		debounce3 = true
		local HousingC = coroutine.create(function()
			target:FindFirstChild("InfoHousing", true).Enabled = true
			local selectionBox = Instance.new("SelectionBox",target)
			selectionBox.Adornee = target 
			selectionBox.Color = BrickColor.new("Lime green")
			repeat wait() until maintarg ~= target and moving == true
			target:FindFirstChild("InfoHousing", true).Enabled = false
			selectionBox:Destroy()
		end)
		coroutine.resume(HousingC)
		debounce3 = false
	end
end

-- Main function below!

mouse.Move:connect(function()
	moving = true
	if not debounce then
		debounce = true
    	if mouse.Target ~= nil then
			local maintarget = mouse.Target.Parent.Parent
			if mouse.Target and mouse.Target.Parent.Parent:FindFirstChild("type0") then -- second mouse.Target is to make sure it's not a skybox.
        		Empty(mouse.Target.Parent.Parent);

			elseif mouse.Target and mouse.Target.Parent.Parent:FindFirstChild("type1") then
        		Storage(mouse.Target.Parent.Parent);

			elseif mouse.Target and mouse.Target.Parent.Parent:FindFirstChild("type2") then
        		Housing(mouse.Target.Parent.Parent);

			else
				maintarg = "Nil"
			end
    	end
		debounce = false
	end
end);

mouse.Idle:connect(function()
	if not debounceI then
		debounceI = true
		moving = false
		debounceI = false
	end
end)

The selection boxes keep sticking on me (meaning they aren't destroyed). Sometimes they will disappear, but usually they'll stick. The Gui, however, goes away most of the time.

Thanks for reading, and I appreciate anybody who is helping with this!

EDIT: Well, the first sticking issue was because I put the debounce# = false after the wrong end. However, the GUIs are now flashing, even when the selection boxes aren't. And, the selection boxes still stick when moving too fast.

1 answer

try checking over ur other debounces... there might be a nil value somewhere or u may have accedentally made it loop

2 comments

0

I've checked through the debounces and values -- to my knowledge, the debounces all work as supposed to, and I've tested values through printing, and haven't received a nil when it wasn't purposeful.

0

o...then im not sure... imnonyl a begginner so i figured i wouldnt be much help... but i tryed

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