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
image_2022-04-01_043532

  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

script.Parent.MouseButton1Click:Connect(function()
	event:FireServer(BlockV)
end)

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 = Instance.new("Frame")
F1.Position = UDim2.fromOffset(mousePos.X,mousePos.Y)
F1.BackgroundTransparency = 1
local F2 = Instance.new("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
print(Amount)

linksFolder.ChildAdded:Connect(function()
	Amount += 1
	print("Folders in links folder:"..Amount)
end)

linksFolder.ChildRemoved:Connect(function()
	Amount -= 1
	print("Folders in links folder:"..Amount)
end)

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

event.OnServerEvent:Connect(function(player,blockName)
	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
			else
				continue
			end
		end
		
	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
			end
		end
	end
	
	createLink(node1,node2)
	
end)

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
end

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
		return
	end
end

local Frame = Instance.new("Frame")

RS.RenderStepped:Connect(function()
	local XLength = F1.AbsolutePosition.X - F2.AbsolutePosition.X
	local YLength = F1.AbsolutePosition.Y - F2.AbsolutePosition.Y
	local Mag = (
		Vector2.new(F1.AbsolutePosition.X, F1.AbsolutePosition.Y) 
		- Vector2.new(F2.AbsolutePosition.X, 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)
end)

Frame.Parent = Parent
Frame.AnchorPoint = Vector2.new(0.5, 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