How to make a double clickdetector

Hello!
I’m making a game teaching the risks of polution and other world issues.
However, I’ve ran into an issue.
If I were to click a block, then click another. I want a rope to attach to both parts I clicked.
How would I do this?

Simply use a bool to detect if one click was done already.

local Clicked = false
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	local Target = Mouse.Target
	if Clicked == false and Target ~= nil then
		--1st side of the rope
	elseif Clicked == true and Target ~= nil then
		--2nd side of the rope
		Clicked = false
	end
end)

Trying to do a clickdetector, not a playerscript

You could create 2 variables that gets set for example

local Attachment1
local Attachment2

The first part you press will be set in Attachment1 while the other attachment2 and set the rope’s attachments to their variables.

But where do I put the script? In one of the parts or in startercharacterscripts?

You could use a BoolValue | Roblox Creator Documentation instead, application is the same.

That was a example, It’s not a code.

Although i’ll provide you a code. Give me a sec.

Can you please send the code so i can modify it and merge it with my example?

Here is the code i’m using

local attach1 = nil
local attach2 = nil
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	local Target = Mouse.Target
	if attach1 == nil then
		attach1 = Target
		local b = Instance.new("Attachment")
		b.Parent = Target
	end
	if attach1 ~= nil and attach2 == nil then
		attach2 = Target
		local a = Instance.new("Attachment")
		a.Parent = Target
	end
end)

What exact do you want to do?
(Char limit…)

once a part is clicked, and then another is
a rope connects between the first part that was clicked and the second part that was clicked

Solved! Thanks for your posts anyways.

local attach1 = nil
local attach2 = nil
local Player = game.Players.LocalPlayer
local Mouse = Player:GetMouse()

Mouse.Button1Down:Connect(function()
	local Target = Mouse.Target
	if attach1 == nil then
		attach1 = Target
		local b = Instance.new("Attachment")
		b.Parent = attach1
		return
	end
	if attach1 ~= nil and attach2 == nil then
		attach2 = Target
		local a = Instance.new("Attachment")
		a.Parent = attach2
		return
	end
end)

this puts an attachment in both of them, but i’ll make it actually attach the rope later.

1 Like

Nice that you actually solved it!

While you got the solution i were working on the code.

2 Likes