Set Beams endpoint on User's Mouse Cursor

Hey! I’m trying to code Beams to have a Starting Point on a Part, and the End Point to be the Mouse Cursor.

		for _,conn in pairs(Connections) do
			if (conn ~= nil) then
				conn:Disconnect()
				conn = nil
			end
		end
		
		Connections["Mouse_Moved"] = Mouse.Move:Connect(function()
			-- checking if selected
			local function check_selected()
				for _,v in pairs(Main.Start:GetChildren()) do
					if (v:FindFirstChild("Dragger")) then
						if v:GetAttribute("Selected") == true then
							return v.Dragger
						end
					end
				end
				return false
			end
			
			local dragger = check_selected()
			
			if (dragger ~= nil and dragger ~= false) then
				warn'test'
				local position = Vector2.new(Mouse.X, Mouse.Y)
				local size = Vector2.new(Mouse.ViewSizeX, Mouse.ViewSizeY)

				local norm = position/size

				print(norm)
				
				dragger.Position = norm
			end
		end)
		

I create a Beam Instance above, and set the Starting Point to an already selected Part. How would I constantly update the End point and set it to the Mouse Cursor?

Create a connection to RenderStepped or of of the new “framerate” events of RunService, which sets the WorldCFrame of the Attachment1 of the Beam to mouse.Hit.

How would you replicate that in Lua?

1 Like
RunS.RenderStepped:Connect(function()
    beam.Attachment1.WorldCFrame = mouse.Hit
end)
1 Like