How to wait until a second button has been pressed after the first one

You can write your topic however you want, but you need to answer these questions:

  1. What do you want to achieve? Keep it simple and clear!

→ im working on a visual scripting plugin and I’m currently working on linking two blocks together and when you click the first block i want the script to wait until a second block is clicked to link them

  1. What is the issue? Include screenshots / videos if possible!

→ when i click the first block it create a folder with only the first node but the second is nil so my script gives me an error

here is the directory if it gonna help

  1. What solutions have you tried so far? Did you look for solutions on the Developer Hub?
    i’ve searched but only found one with a click detector not a gui and i don’t think that there is something there that could help me

After that, you should include more details if you have any. Try to make your topic as descriptive as possible, so that it’s easier for people to help you!

this is the local script that sends the event to the server when a block is clicked

local linksFolder  = script.Parent.Parent.Parent.Links
local event = linksFolder.RemoteEvent
local BlockV = script.Parent.Parent.Value.Value


and there is the script

local event = script.Parent.RemoteEvent
local linksFolder = script.Parent
local background = script.Parent.Parent
local uis = game:GetService("UserInputService")
local mousePos = uis:GetMouseLocation()
local F1 ="Frame")
F1.Position = UDim2.fromOffset(mousePos.X,mousePos.Y)
F1.BackgroundTransparency = 1
local F2 ="Frame")
F2.Position = UDim2.fromOffset(mousePos.X,mousePos.Y)
F2.BackgroundTransparency = 1

local node1 = nil
local node2 = nil
local LineRenderer = script.LineRenderer

local Amount = #linksFolder:GetChildren() - 3

	Amount += 1
	print("Folders in links folder:"..Amount)

	Amount -= 1
	print("Folders in links folder:"..Amount)

local function createLink(V1,V2)
	local folder ="Folder")
	folder.Name = "link"..Amount
	folder.Parent = linksFolder
	local origin1 ="StringValue")
	origin1.Name = "Link01"
	origin1.Value = tostring(V1)
	origin1.Parent = folder
	local origin2 ="StringValue")
	origin2.Name = "Link02"
	origin2.Value = tostring(V2)
	origin2.Parent = folder
	local scriptClone = LineRenderer:Clone()
	scriptClone.Parent = folder
	scriptClone.Disabled = false

	if node1 == nil then
		for i,v in pairs(background:GetDescendants()) do
			if v:IsA("StringValue") and v.Value == blockName then
				node1 = v.Parent.Name
	elseif node1 ~= nil and node2 == nil then
		for i,v in pairs(background:GetDescendants()) do
			if v:IsA("StringValue") and v.Value == blockName then
				node2 = v.Parent.Name

then i have a local script that renders the line

local RS = game:GetService("RunService")

local player = game.Players.LocalPlayer
local mouse = player:GetMouse()
local UserInputService = game:GetService("UserInputService")
local mouseLocation = UserInputService:GetMouseLocation()
local background = script.Parent.Parent.Parent

local Parent = script.Parent
local l1 = script.Parent.Link01
local l2 = script.Parent.Link02
local F1 = nil
local F2 = nil

local function DivideSmaller(X, Y)
	return math.atan2(Y, X) * 180 / math.pi

for i, v in pairs(background:GetDescendants()) do
	if v:IsA("StringValue") and v.Name == "Value" and  v.Value == l1.Value then
		F1 = v.Parent.Link
	elseif v:IsA("StringValue") and v.Name == "Value" and v.Value == l2.Value then
		--F2 = v.Parent.Link

local Frame ="Frame")

	local XLength = F1.AbsolutePosition.X - F2.AbsolutePosition.X
	local YLength = F1.AbsolutePosition.Y - F2.AbsolutePosition.Y
	local Mag = (, F1.AbsolutePosition.Y) 
		-, F2.AbsolutePosition.Y)
	local CenterPosition = (F2.AbsolutePosition + F1.AbsolutePosition) / 2
	Frame.Rotation = DivideSmaller(XLength, YLength)
	Frame.Position = UDim2.fromOffset(CenterPosition.X, CenterPosition.Y)
	Frame.Size = UDim2.fromOffset(Mag.Magnitude, 1)

Frame.Parent = Parent
Frame.AnchorPoint =, 0.5)

okaaayyy i found the problem i was calling the function that create a folder everytime the remote event is fired i’ve added some print() to help me to found the problem soo i’ve made that the function is called only when node1 and node 2 are not equal to nil then when the folder is created i reset the values to nil again