I’m making some code right now for a selection system and it isn’t working.
The events print and duplicate twice, despite me adding a debounce. This immediately gets rid of the highlight and the debounce also breaks for some reason.
local debouncev = false
local function debounce()
task.wait(0.2)
debounce = false
print("Debounced")
end
mouse.Button1Up:Connect(function()
local target = mouse.Target
if target and debouncev == false then
debouncev = true
local ctrlDown = game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftControl)
local altDown = game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftAlt)
if altDown then
print("rr")
debounce()
else
if target:FindFirstChild("CreateHighlight") then
target:FindFirstChild("CreateHighlight"):Destroy()
debounce()
else
if #selectedParts > 0 then
selectedParts = {}
end
table.insert(selectedParts, target:GetFullName())
local highlightClone = highlightPath:Clone()
highlightClone.Parent = target
print(highlightClone:GetFullName())
print(selectedParts)
debounce()
end
end
end
end)
I’ve tried adding a debounce and such, but it didn’t work.
Hi, while the function doesn’t repeat twice now, after the debounce I can’t click at all.
local function debounce()
task.delay(0.2,function()
debounce = false
end)
end
mouse.Button1Up:Connect(function()
local target = mouse.Target
if target and debouncev == false then
debouncev = true
local ctrlDown = game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftControl)
local altDown = game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftAlt)
if altDown then
print("rr")
debounce()
else
if target:FindFirstChild("CreateHighlight") then
target:FindFirstChild("CreateHighlight"):Destroy()
debounce()
else
if #selectedParts > 0 then
selectedParts = {}
end
table.insert(selectedParts, target:GetFullName())
local highlightClone = highlightPath:Clone()
highlightClone.Parent = target
print(highlightClone:GetFullName())
print(selectedParts)
debounce()
end
end
end
end)
Ok, so it sort of half works and half doesnt [and sorry about not realising about debouncev].
This is attached to a gear in a PlayerGui, and I have to retoggle the gear to be able to use the function again, because despite the debounce it will still report itself true [even after changing debouncev].
mouse.Button1Up:Connect(function()
print(debouncev)
local target = mouse.Target
if target and debouncev == false then
debouncev = true
local ctrlDown = game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftControl)
local altDown = game:GetService("UserInputService"):IsKeyDown(Enum.KeyCode.LeftAlt)
if altDown then
print("rr")
else
if target:FindFirstChild("CreateHighlight") then
target:FindFirstChild("CreateHighlight"):Destroy()
else
if #selectedParts > 0 then
selectedParts = {}
end
table.insert(selectedParts, target:GetFullName())
local highlightClone = highlightPath:Clone()
highlightClone.Parent = target
print(highlightClone:GetFullName())
print(selectedParts)
end
end
debounce()
end
end)