Double click bug?

I want to know why this happens, here is the video and the script, (I’m new to programming)

local Text = script.Parent
local Dummy = require(Text.AllGameDialogues)
Text.Visible = false

game.Workspace.Dummy2.ProximityPrompt.Triggered:Connect(function()
	local Value = 0
	Value = 0
	Text.Visible = true
	Text.Next.MouseButton1Click:Connect(function()
		Value += 1
		print(Value)
		if Value == 2 then
			Text.Visible = false
		end
	end)
end)

You’re connecting a new MouseButton1Click event handler every time the proximity prompt is triggered. You could try putting the MouseButton1Click event outside of the Triggered event or you could store a reference to the MouseButton1Click connection outside of the function and then disconnect the old one before connecting a new one

local Text = script.Parent
local Dummy = require(Text.AllGameDialogues)
Text.Visible = false

local Connection
game.Workspace.Dummy2.ProximityPrompt.Triggered:Connect(function()
	local Value = 0
	Value = 0
	Text.Visible = true
	if Connection then
		Connection:Disconnect()
		Connection = nil
	end
	Connection = Text.Next.MouseButton1Click:Connect(function()
		Value += 1
		print(Value)
		if Value == 2 then
			Text.Visible = false
		end
	end)
end)
1 Like