ClickDetector fires twice

Hey,

I notice that whenever i click on a part that has a clickdetector (specificly right click) it sometimes fires twice event three times.

Here is the code i whrote:

local debounce = false

script.Parent.ClickDetector.RightMouseClick:Connect(function(player)
        print("Left Clicked")
	local Side = player:WaitForChild("Side")
	if debounce == false then
		if Side.Ghoul.Value == true then
			debounce = true
			local GhoulData = player:WaitForChild("GhoulData")
			local StatPoints = GhoulData:WaitForChild("StatPoints")

			StatPoints.Value += 100
		else
			debounce = true
			local CCGData = player:WaitForChild("CCGData")
			local StatPoints = CCGData:WaitForChild("StatPoints")

			StatPoints.Value += 100
		end
		delay(0.1, function()
			debounce = false
		end)
	end
end)

Here you can see what the console gives me when i right click the part:

I know that my script works because i added a debounce but i whould like to know why is that happening, Also take a note that the script is running from a server script inside the part.

I also tested in a Client script and it does the same.

Any suggestion whould be greatly appreciated!

Right click but it prints left click?

I don’t get this issue.

1 Like

My bad its suposed to say Right Clicked, my issue though its that whenever i right or left click it sometimes fires the function more that one time for some reason.

1 Like

I actually found out that there is no problem in my script and its just that my mouse is broken :confused:

1 Like

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.